note 67939 added to language.variables.scope

From: Date: Fri, 07 Jul 2006 02:48:19 +0000
Subject: note 67939 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-114526@lists.php.net to get a copy of this message
In response to: Variable scope Quote: "the global keyword *will* allow you to access variables in the global scope of your script, even if those variables were not made available locally to the parent function." Actually, the "parent" function does not access a variable in its global scope unless it specifically uses the global modifier on the variable. See this test: <?php $var = ''; // global scope function foo() { $var = 'Hello from $foo'; bar(); echo $var; } function bar() { global $var; $var = 'Hello from $var'; } foo(); // prints: "Hello from $foo" ?> The global scope of the variable $var is only available to bar(), not to foo(). Even if you were to put foo() and bar() in the same parent class, this would still be the case. ---- Server IP: 64.71.164.2 Probable Submitter: 68.118.73.81 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/note/edit/67939 Del: integrated -- http://master.php.net/note/delete/67939/integrated Del: useless -- http://master.php.net/note/delete/67939/useless Del: bad code -- http://master.php.net/note/delete/67939/bad+code Del: spam -- http://master.php.net/note/delete/67939/spam Del: non-english -- http://master.php.net/note/delete/67939/non-english Del: in docs -- http://master.php.net/note/delete/67939/in+docs Del: other reasons-- http://master.php.net/note/delete/67939 Reject -- http://master.php.net/note/reject/67939 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114526) next »