ID:               45930
 Updated by:       [EMAIL PROTECTED]
 Reported By:      waxtonmax at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Session related
 Operating System: windows vista
 PHP Version:      5.2.6
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------

[2008-08-27 06:18:24] waxtonmax at yahoo dot com

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 this bug report at http://bugs.php.net/?id=45930&edit=1

Reply via email to