note 85203 added to language.variables.scope

From: Date: Wed, 20 Aug 2008 03:15:02 +0000
Subject: note 85203 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-143666@lists.php.net to get a copy of this message
Note that if you declare a variable in a function, then set it as global in that function, its value will not be retained outside of that function. This was tripping me up for a while so I thought it would be worth noting. <?PHP foo(); echo $a; // echoes nothing bar(); echo $b; //echoes "b"; function foo() { $a = "a"; global $a; } function bar() { global $b; $b = "b"; } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 71.109.251.34 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/85203 Del: integrated -- https://master.php.net/note/delete/85203/integrated Del: useless -- https://master.php.net/note/delete/85203/useless Del: bad code -- https://master.php.net/note/delete/85203/bad+code Del: spam -- https://master.php.net/note/delete/85203/spam Del: non-english -- https://master.php.net/note/delete/85203/non-english Del: in docs -- https://master.php.net/note/delete/85203/in+docs Del: other reasons-- https://master.php.net/note/delete/85203 Reject -- https://master.php.net/note/reject/85203 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143666) next »