From: Operating system: debian PHP version: 5.3.3 Package: Reproducible crash Bug Type: Bug Bug description:multiple instances made with a singleton
Description: ------------ Hello, first off, ive been searching but i couldnt find any related bugreport and im sorry if i wasted your time. I have 2 classes with both an singleton function in them, an api (test) and a user (test2) class. The api uses the user data and the user class uses the api to get its userdata. Hence i load the user class instance in the api and vice versa. It works if i use an external class to serve as a singleton storage but if i use the static $instance it doesnt. The singleton function does work when i remove the test2::getInstance() from class test. Test script: --------------- class test { private static $instance; private $test2; private function __construct() { $this->test2 = test2::getInstance(); } public static function getInstance() { if (!isset(self::$instance)) { echo '<br>new test instance'; $c = __CLASS__; self::$instance = new $c; } return self::$instance; } } class test2 { private static $instance; private $test; private function __construct() { $this->test = test::getInstance(); } public static function getInstance() { if (!isset(self::$instance)) { echo '<br>new test2 instance'; $c = __CLASS__; self::$instance = new $c; } return self::$instance; } } print 'start:<br>'; for ($i = 1; $i < 10; $i++) { print '<br>loop: '.$i; $t = test::getInstance(); } Expected result: ---------------- start: loop: 1 new test instance new tes2 instance loop: 2 loop: 3 loop: 4 loop: 5 loop: 6 loop: 7 loop: 8 loop: 9 Actual result: -------------- start: loop: 1 new test instance new test2 instance new test instance new test2 instance new test instance new test2 instance new test instance new test2 instance new test instance new test2 instance ... till php runs out of memory -- Edit bug report at http://bugs.php.net/bug.php?id=52653&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52653&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52653&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52653&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52653&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52653&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52653&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52653&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52653&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52653&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52653&r=support Expected behavior: http://bugs.php.net/fix.php?id=52653&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52653&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52653&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52653&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52653&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52653&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52653&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52653&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52653&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52653&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52653&r=mysqlcfg