note 56749 added to language.variables.scope

From: Date: Wed, 14 Sep 2005 10:06:25 +0000
Subject: note 56749 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-95155@lists.php.net to get a copy of this message
Pay attention while unsetting variables inside functions: <?php $a = "1234"; echo "<pre>"; echo "outer: $a\n"; function testa() { global $a; echo " inner testa: $a\n"; unset ($a); echo " inner testa: $a\n"; } function testb() { global $a; echo " inner testb: $a\n"; $a = null; echo " inner testb: $a\n"; } testa(); echo "outer: $a\n"; testb(); echo "outer: $a\n"; echo "</pre>"; ?> /***** Result: outer: 1234 inner testa: 1234 inner testa: outer: 1234 inner testb: 1234 inner testb: outer: ******/ Took me 1 hour to find out why my variable was still there after unsetting it ... Thomas Candrian ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56749 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56749&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56749&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95155) next »