Re: Re: PHP 4.0 Bug #5289 Updated: Use of reset on a global array creates

From: Date: Fri, 30 Jun 2000 11:07:26 +0000
Subject: Re: Re: PHP 4.0 Bug #5289 Updated: Use of reset on a global array creates
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-23028@lists.php.net to get a copy of this message
Yes Rick, I thought of that one myself last night (are we telepathic?) Can anyone tell me if there's any memory penalty in doing this instead of using unset()? (the arrays iteratively replaced could be quite chunky). If there is no downside, replacing the arrays by simple re-assignment to an empty array would be the best solution. It remains a difference between php3 and php4, meaning I have to devise a global search for any such use of unset() in all my projects... So, as I now understand it: unset($var) means "destroy this variable, as if it were never used" after which: isset($var) would return false echo $var would echo null when declared as global inside a function further references inside a function will refer to a local variable, not a global one. As it happens I think $var=array() has superior syntax over unset($var) in that (usually) parameters referenced by value cannot be altered by a function. unset() isn't really a function, more a parser control element, like include(). Thanks Alan php4@developersdesk.com wrote: > > Addressed to: alan.frostick@iconmedialab.com > Bug Database <php-dev@lists.php.net> > > ** Reply to note from Alan Frostick <alan.frostick@iconmedialab.com> Thu, 29 Jun 2000 > 22:05:54 +0200 > > > > That may be the new definition, but it wasn't the case under php3. I > > didn't spot anything in your differences notes for this. > > > > My code fragment just highlights the > > problem, it's actually gleaned from debugging a much larger and > > complex script. What I want to do is replace an array with fresh > > contents when a loading function is invoked. This is most simply done > > by using unset. > > > Is there a better way to do it? > > <Wild Guess Alert!> > > Have you considered: > > function whatever() { > global $MyGlobalArray; > > $MyGlobalArray = array(); > > .. > .. > .. > > } > > Don't unset it, just replace its contents with an empty array... > > </Wild Guess Alert!> > > Rick Widmer > Internet Marketing Specialists > http://www.developersdesk.com -- Alan Frostick Icon Medialab AG Hamburg Gasstr.4 D- 22761 Hamburg Germany home: http://www.iconmedialab.de mailto:alan.frostick@iconmedialab.com phone: +49- (0)40- 8979- 8219 fax: +49- (0)40- 8979- 8989

« previous php.dev (#23028) next »