note 109967 added to language.oop5.magic

From: Date: Thu, 06 Sep 2012 12:12:23 +0000
Subject: note 109967 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-190536@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 77.37.176.31 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/109967 Del: integrated -- https://master.php.net/note/delete/109967/integrated Del: useless -- https://master.php.net/note/delete/109967/useless Del: bad code -- https://master.php.net/note/delete/109967/bad+code Del: spam -- https://master.php.net/note/delete/109967/spam Del: non-english -- https://master.php.net/note/delete/109967/non-english Del: in docs -- https://master.php.net/note/delete/109967/in+docs Del: other reasons-- https://master.php.net/note/delete/109967 Reject -- https://master.php.net/note/reject/109967 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190536) next »