Bug #12454: Static references are transient inside methods

From: Date: Sun, 29 Jul 2001 09:14:19 +0000
Subject: Bug #12454: Static references are transient inside methods
Groups: php.dev 
Request: Send a blank email to php-dev+get-61355@lists.php.net to get a copy of this message
From: nick@macaw.demon.co.uk Operating system: Linux PHP version: 4.0.6 PHP Bug Type: Variables related Bug description: Static references are transient inside methods Another unfortunate bug with references appears to be that statics holding references inside methods are actually transient, and a reference will be lost. For example, calling the following code several times will initialise $db and return every time with a new instance. function &getInstance() { static $db; if (!isset($db)) { $db =& new FS_DB(); } return $db; } whereas the following will give true singeton behaviour and initialise just once, as expected. function &getInstance() { static $db; if (!isset($db)) { $db = new FS_DB(); } return $db; } -- Edit bug report at: http://bugs.php.net/?id=12454&edit=1

« previous php.dev (#61355) next »