PHP Call closure under stdClass -
this have
$x = new \stdclass(); $x->cast = function($y){ return $y; }; and when try execute it
$x->cast(5); i error
fatal error: call undefined method stdclass::cast()
how can fix it?
in general it's nicer make class if want attach functions objects in case want should work:
$x = new \stdclass(); $x->cast = function($y){ return $y; }; $y = $x->cast; var_dump($y(5)); or
call_user_func($x->cast, 5);
Comments
Post a Comment