我想知道为什么这个不起作用:(
但是这个有效:
PHP致命错误:调用未定义的方法stdClass::y()
)$x=new stdClass;
$x->y=function(){return 'hi';};
echo $x->y();
但是这个有效:
$x=new stdClass;
$x->y=function(){return 'hi';};
$y=$x->y;
echo $y();
echo ($x->y)();
也会返回Parse error: syntax error, unexpected '(', expecting ',' or ';'
无效。那么,如何在没有中间变量的情况下正确调用y
闭包属性呢?
call_user_func($x->y)
。 - deceze