|  | Posted by steve on 06/15/99 11:20 
"Kimmo Laine" <eternal.erectionN05P@Mgmail.com> wrote in message news:DVtye.2045$455.1532@reader1.news.jippii.net...
 | "Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
 | news:dadovd$8n8$1@news.onet.pl...
 | >> Steve wrote:
 | >> > Say you have defined a variable $var in your main script.
 | >> >
 | >> > Now in a function you access it using:
 | >> > global $var;
 | >> >
 | >> > But you want to set it to null inside the function.
 | >> > DO:   $var = null;
 | >> > DONT DO:  unset($var);
 | >> >
 | >> > Why?  Because the 2nd way removes the variable from the name space,
 | >> > and it is no longer globally available. Cost me 10 hours....
 | >
 | > Kimmo Laine wrote:
 | >> That's odd. The manual seems to disagree:
 | >>
 | >> "If a globalized variable is unset() inside of a function, only the
 local
 | >> variable is destroyed. The variable in the calling environment will
 | >> retain the same value as before unset() was called.
 | >>
 | >> <?php
 | >> function destroy_foo()
 | >> {
 | >>   global $foo;
 | >>   unset($foo);
 | >> }
 | >>
 | >> $foo = 'bar';
 | >> destroy_foo();
 | >> echo $foo; // prints "bar"
 | >> ?>"
 | >> - from http://fi.php.net/manual/en/function.unset.php
 | >
 | > That's exactly what Steve said. He said that the variable is removed
 | > from current namespace (function namespace), not that it's totaly
 | > removed.
 |
 |
 | I somehow thought he meant from the entire namespace, not from current...
 | Okay, my bad. Now it all makes sense.
 
 hmmm...i don't believe you have mis-read anything. i read steve's op that
 same way you did *and* the problem he describes *does* conflict with the php
 manual. but then again, we may both be having problems with our reading
 comprehension. ;^)
  Navigation: [Reply to this message] |