note 65337 added to language.variables.scope

From: Date: Fri, 28 Apr 2006 22:53:35 +0000
Subject: note 65337 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-110044@lists.php.net to get a copy of this message
This is probably self-evident to most folks here, and I expected this behavior, but it wasn't explicitly mentioned in the manual itself so I tested to find out: 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. In other words, the following will work as expected, even though $a is never referenced as global within the function foo: <?php function foo() { bar(); } function bar() { global $a; echo $a; } $a = "works!"; foo(); ?> ---- Server IP: 216.194.113.175 Probable Submitter: 64.58.3.6 ---- 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/65337 Del: integrated -- http://master.php.net/note/delete/65337/integrated Del: useless -- http://master.php.net/note/delete/65337/useless Del: bad code -- http://master.php.net/note/delete/65337/bad+code Del: spam -- http://master.php.net/note/delete/65337/spam Del: non-english -- http://master.php.net/note/delete/65337/non-english Del: in docs -- http://master.php.net/note/delete/65337/in+docs Del: other reasons-- http://master.php.net/note/delete/65337 Reject -- http://master.php.net/note/reject/65337 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110044) next »