ID:               27724
 Updated by:       [EMAIL PROTECTED]
 Reported By:      leonel at nied dot unicamp dot br
-Status:           Feedback
+Status:           No Feedback
 Bug Type:         Zend Engine 2 problem
 Operating System: Fedora Core1
 PHP Version:      5.0.0RC1
 New Comment:

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.




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

[2004-04-13 13:06:01] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip



------------------------------------------------------------------------

[2004-03-28 02:05:54] jewfish at jewfish dot net

I have seen this bug in PHP 4 as well (encountered it the same day you
posted this bug, in fact).  It can be verified to be in PHP 4 in much
the same way.

------------------------------------------------------------------------

[2004-03-27 11:50:55] kase at gmx dot net

Works well using this code:

kasedebian:/var/www# cat test.php5
<?php
class IntegerFactory {
        private static $int = NULL;

        function __construct() {}

        public function getInstance() {
                if ( !isset(IntegerFactory::$int) ) {
                        echo 'null !', "\n"; IntegerFactory::$int = new
IntegerFactory;
                }
                return IntegerFactory::$int;
        }
}

$tmp1 = new IntegerFactory;
$d1 = $tmp1->getInstance();
var_dump($d1);
$tmp2 = new IntegerFactory;
$d2 = $tmp2->getInstance();
var_dump($d2);
$d3 = $tmp1->getInstance();
var_dump($d3);
?>

------------------------------------------------------------------------

[2004-03-26 15:21:46] leonel at nied dot unicamp dot br

Funny enough, I remember now that I got this code from an article from
Andy Gutsman himself:

http://www.zend.com/php5/andi-book-excerpt.php (see 10.static members)

------------------------------------------------------------------------

[2004-03-26 15:20:13] leonel at nied dot unicamp dot br

Description:
------------
I tried to implement a class with the Singleton pattern. However,
static variables do not seem to tie to the class, but rather to the
instance of the class.

Looking at bug 16245
  http://bugs.php.net/bug.php?id=16245&edit=2
I see that Mr. Flying and I have sort of 'exchanged' bugs. He got the
result I expected and I got the result he expected.
Notice 2 things: first, he assigned a primitive type to his variable,
whereas my variable holds an object; second, his variable is declared
inside the function, and mine is declared inside the class.

Reproduce code:
---------------
<?php
class IntegerFactory {
    private static $int = NULL;
    function __construct() {}
    public function getInstance() {
        if ( !isset($this->int) ) {
            echo 'null !', "\n"; $this->int = new IntegerFactory;
        }
        return $this->int;
    }
}
$tmp1 = new IntegerFactory;
$d1 = $tmp1->getInstance();
var_dump($d1);
$tmp2 = new IntegerFactory;
$d2 = $tmp2->getInstance();
var_dump($d2);
$d3 = $tmp1->getInstance();
var_dump($d3);
?>

Expected result:
----------------
null !
object(IntegerFactory)#2 (0) {
}
object(IntegerFactory)#2 (0) {
}
object(IntegerFactory)#2 (0) {
}


Actual result:
--------------
null !
object(IntegerFactory)#2 (0) {
}
null !
object(IntegerFactory)#4 (0) {
}
object(IntegerFactory)#2 (0) {
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27724&edit=1

Reply via email to