ID:               37383
 Updated by:       [EMAIL PROTECTED]
 Reported By:      patrick at factorylabs dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
-Operating System: Windows
+Operating System: *
-PHP Version:      5.1.4
+PHP Version:      *
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php




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

[2006-05-09 15:51:20] patrick at factorylabs dot com

Description:
------------
Given a member function of a class that has a static variable; the
value of the static variable, when changed, is propagated to all object
instances of the class.  (note: may be a duplicate of #16245)

The code below is strictly intended to demonstrate this issue (having a
static variable in a constructor is pointless).

Note that removing the static key word from the $bSwitch declaration
causes the $bSwitch variable to operate with a scope that is unique to
the instance of the class.



Reproduce code:
---------------
define('endl', "\n");

class CMyWidget {
    public function __construct() {
        static $bSwitch = false;
        echo '$bSwitch = ' . ($bSwitch ? 'true' : 'false') . endl;
        if($bSwitch === false)
            $bSwitch = true;
    }
}

$oTest1 = new CMyWidget();
$oTest2 = new CMyWidget();

Expected result:
----------------
$bSwitch = false
$bSwitch = false

Actual result:
--------------
$bSwitch = false
$bSwitch = true


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


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

Reply via email to