#42937 [NEW]: __call() method not invoked when methods are called on parent from child class

From: Date: Thu, 11 Oct 2007 23:08:54 +0000
Subject: #42937 [NEW]: __call() method not invoked when methods are called on parent from child class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118435@lists.php.net to get a copy of this message
From: jmaxwilson at sixteensmallstones dot org Operating system: Windows XP PHP version: 5.2.4 PHP Bug Type: Scripting Engine problem Bug description: __call() method not invoked when methods are called on parent from child class Description: ------------ If __call() is used to implement a method in a parent class, and the method is overridden in an inherited child class using a real method declaration that calls parent::methodName(), __call() is never invoked and PHP reports a fatal error saying that the method is undefined. You can work around the bug by replacing parent::methodName() with parent::__call('methodName',null), but it means that you have to know which of the parent's methods are implemented using __call() in order to override them in a child class. The child class should be agnostic to whether the parent's methods are real or magic. This bug was reported in PHP5.1 RC1 (http://bugs.php.net/bug.php?id=34739) but was improperly marked as bogus with the explanation that "__call() is not used when calling static methods." The use of the paamayim-nekudotayim (::) with the parent keyword is not to resolve static scope but to resolve inherited scope for an overridden method, therefore the issue should be reconsidered. Reproduce code: --------------- <?php class A { function __call($strMethod, $arrArgs) { return "PHP " .phpversion(); } } class B extends A { function getVersion() { return parent::getVersion() . " Rocks!"; } } $A = new A(); echo $A->getVersion() . "<br/>"; $B = new B(); echo $B->getVersion() . "<br/>"; ?> Expected result: ---------------- PHP 5.2.4 PHP 5.2.4 Rocks! Actual result: -------------- PHP 5.2.4 Fatal error: Call to undefined method A::getversion() in C:\www\test.php on line 10 -- Edit bug report at http://bugs.php.net/?id=42937&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42937&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42937&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42937&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42937&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42937&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42937&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42937&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42937&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42937&r=support Expected behavior: http://bugs.php.net/fix.php?id=42937&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42937&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42937&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42937&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42937&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42937&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42937&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42937&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42937&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42937&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42937&r=mysqlcfg

« previous php.bugs (#118435) next »