Quoting Andrei:
Static variables are references, so you should not use &new 
when assigning to them, same as with global variables.

sorry for the fuzz :)

- Markus

On Wed, Aug 15, 2001 at 02:09:26AM +0200, Sebastian Bergmann wrote : 
>   Consider the following code
> 
>     <?php
>       class foo {
>         function foo() {}
>       }
>     
>       function contains_static() {
>         static $bar;
>         echo '1'.$bar.'<br>';
>     
>         $bar =& new foo();
>         echo '2'.$bar.'<br>';
>       }
>     
>       contains_static();
>       contains_static();
>     ?>
> 
>   When $bar is assigned as above (with a &), this outputs
> 
>     1
>     2Object
>     1
>     2Object
> 
>   Clearly, the static variable loses its contend between the two
>   calls.
> 
>   After removing the & the output looks as follows
> 
>     1
>     2Object
>     1Object
>     2Object
> 
>   Now the question: Is this a bug and assignment to a static
>   variable by reference should work, or is this intended
>   behaviour since after the scope of contains_static() the
>   reference count is decreased, and bla bla ?
> 
>   You can easily find argument for both variants, hence the
>   question.
> 
> -- 
>   Sebastian Bergmann                     Measure Traffic & Usability
>   http://sebastian-bergmann.de/            http://phpOpenTracker.de/
> 
> -- 
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Markus Fischer,  http://guru.josefine.at/~mfischer/
EMail:         [EMAIL PROTECTED]
PGP Public  Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1  C2B5 D674 B445 C227 2BD0
              -All your scripts are belong to Zend-

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to