【发布时间】:2023-03-25 13:16:02
【问题描述】:
我想知道为什么这不起作用:(PHP Fatal error: Call to undefined method 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 闭包属性的正确方法是什么。
【问题讨论】:
-
o.O 这是下一级的扭曲用法
-
替代:
call_user_func($x->y).