note 109967 deleted from language.oop5.magic by cmb
| From: | cmb@php.net | Date: | Sun, 10 Nov 2019 12:38:08 +0000 |
| Subject: | note 109967 deleted from language.oop5.magic by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212985@lists.php.net to get a copy of this message | ||
Note Submitter: qfox at ya dot ru
----
For those of you who have the same trouble as osbertv.
<?php
// ...
$a = new A();
$b = new B();
$a();
$b();
$b->a();
?>
PHP Fatal error: Call to undefined method B::a()
It's because PHP have bug in parsing syntax (a lot of).
Just make it easier to parse and it would work.
For example, like this:
<?php
$c = $b->a;
$c();
?>
Or this, if you use 5.4 (if you using 5.3 just move call function to the each class which need it or
to some base abstract class):
<?php
trait TInnerClosuresInvoker {
function __call($method, $args) {
if (isset($this->$method) && is_callable($method)) {
$closure = $this->$method;
call_user_func_array($closure, $args);
} else {
trigger_error('Call to undefined method
'.__CLASS__.'::'.$method.'()', E_USER_ERROR);
}
}
}
class A {
use TInnerClosuresInvoker;
...
}
?>
It's a little bit dirty, but it works.