Answer the question
In order to leave comments, you need to log in
Why doesn't PHP code with closures work?
Is this due to a feature of PHP, or maybe StdClass just doesn't allow you to do such tricks? Or just 5.6 does not know how? (ps. I try to write in js notation)
$obj = new StdClass();
$obj->fn = new StdClass();
$obj->fn->move = function ($a, $b) {
print_r($this);
return $a * $b;
};
print_r($obj->fn->move(1,2));
Fatal error: Call to undefined method stdClass::move() in [file] on line [line]
Answer the question
In order to leave comments, you need to log in
StdClass cannot add methods.
When I see code like this, I'm really shaking.
this is not js for you, here you can create normal human named classes.
UPD: only for sports purposes I will show how it can work
$f = $obj->fn->move;
print_r($f(1,2));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question