Bug #12454 Updated: Static references are transient inside methods
| From: | mfischer@php.net | Date: | Sat, 02 Mar 2002 01:10:26 +0000 |
| Subject: | Bug #12454 Updated: Static references are transient inside methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-1443@lists.php.net to get a copy of this message | ||
ID: 12454
Updated by: mfischer@php.net
Reported By: nick@macaw.demon.co.uk
Status: Open
-Bug Type: Variables related
+Bug Type: Documentation problem
Operating System: Linux
PHP Version: 4.0.6
New Comment:
Making this a documentation problem.
Static variables just can't hold references of any kind.
For objects it's avoidable with ZE2 because of the new object model.
Previous Comments:
------------------------------------------------------------------------
[2001-07-29 05:14:19] nick@macaw.demon.co.uk
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 this bug report at http://bugs.php.net/?id=12454&edit=1