|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-05-09 18:11 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 04:00:02 2025 UTC |
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