note 67939 deleted from language.variables.scope by danbrown

From: Date: Mon, 18 May 2009 01:36:14 +0000
Subject: note 67939 deleted from language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155559@lists.php.net to get a copy of this message
Note Submitter: variable_scope-php dot net at fijiwebdesign dot com ---- 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.

« previous php.notes (#155559) next »