Re: Bug or Intended Behaviour?

From: Date: Wed, 15 Aug 2001 00:35:10 +0000
Subject: Re: Bug or Intended Behaviour?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-63207@lists.php.net to get a copy of this message
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: 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 -- Markus Fischer, http://guru.josefine.at/~mfischer/ EMail: mfischer@guru.josefine.at 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-

« previous php.dev (#63207) next »