Re: Bug #12454: Static references are transient inside methods
| From: | Ramsi Sras | Date: | Mon, 30 Jul 2001 08:03:09 +0000 |
| Subject: | Re: Bug #12454: Static references are transient inside methods | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-61455@lists.php.net to get a copy of this message | ||
UNSUBSCRIBE ME PLEASE!!!!!!!!!!!!!!
nick@macaw.demon.co.uk schrieb:
> 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
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net