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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -