From: magical...@php.net Operating system: Linux x86_64 PHP version: 5.3.0 PHP Bug Type: Scripting Engine problem Bug description: Late Static Binding class name problem
Description: ------------ In some cases the class name as returned by get_called_class() is incorrect. Can't explain this clearly without more sleep, but the following reproduction code should help understanding the problem. I tried to simplify the code, but the bug disappears in this case. Expected behaviour is to have class C constructed, then class B constructed, with a nice "Here is B\n" displayed. In reality the B::getInstance() static call done from C::__construct doesn't change the classname for LSB, meaning that when Singleton::getInstance() will call get_called_class() it will receive "C" (and letting us enter into an infinite recursion). Reproduce code: --------------- <?php abstract class Singleton { private static $singleton = array(); public function getInstance() { $class = get_called_class(); if (!isset(self::$singleton[$class])) { self::$singleton[$class] = new $class(); } return self::$singleton[$class]; } abstract protected function __construct(); } class B extends Singleton { protected function __construct() { echo "Here is B\n"; } } class C extends Singleton { protected function __construct() { B::getInstance(); } } C::getInstance(); Expected result: ---------------- Here is B Actual result: -------------- Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in foo.php on line 25 -- Edit bug report at http://bugs.php.net/?id=49204&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49204&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49204&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49204&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49204&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49204&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49204&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49204&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49204&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49204&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49204&r=support Expected behavior: http://bugs.php.net/fix.php?id=49204&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49204&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49204&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49204&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49204&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49204&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49204&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49204&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49204&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49204&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49204&r=mysqlcfg