From: waxtonmax at yahoo dot com Operating system: windows vista PHP version: 5.2.6 PHP Bug Type: Session related Bug description: Problem in Singletion object creation
Description: ------------ Hi I have problem in singleton object creation. I having Apache and PHP 5.2.5 Below is the singleton code. ========== CODE =============== POSTED HERE ========== CODE =============== Problem: i have opened a new browser and triggered this class, for the first time the result is fine, ie output was Intializing .... Now for the second time when i refreshed the page agiain it is displaying the same output, it is not entering the else part in the "static function getInstance() ". Also i have opened another browser at the same time , and again trigger this class , and also i am getting same dam.. output.. === Doubts============ 1) will PHP create a singleton object for per session or for entire engine (like singleton object in java for entire JVM). 2) if the singleton object is for entire engine , why it is getting initialized when i triggered the same class from some other browser,(ie) it should not echo "initializing ..." , it should echo "Already init ()". === Doubts============ Please describe me what is happening here. Regards waxtonmax Reproduce code: --------------- <?php class Logger { static private $singleton; private function __construct() { } private function __clone() { } static function getInstance() { echo " ENTERING FOR GET INSTANCE.."."<br>"; if(Logger::$singleton == null) { echo "Intializing ...."."<br>";; Logger::$singleton = new Logger(); } else { echo " Already init ()"."<br>";; } return Logger::$singleton; } /** * */ public function logWriter($serverity , $errMsg) { // DO SOME THING } } Logger::getInstance()->logWriter(1, "This is the file content" ); ?> Expected result: ---------------- Same instance should used across all the session. ie where new request come from different user, the same instance which is instantiated first should be used Actual result: -------------- But new instance is created for every new request for the same session . -- Edit bug report at http://bugs.php.net/?id=45930&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45930&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45930&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45930&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45930&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45930&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45930&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45930&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45930&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45930&r=support Expected behavior: http://bugs.php.net/fix.php?id=45930&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45930&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45930&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45930&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45930&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45930&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45930&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45930&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45930&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45930&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45930&r=mysqlcfg