note 101385 added to language.variables.scope

From: Date: Tue, 14 Dec 2010 06:10:05 +0000
Subject: note 101385 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-174894@lists.php.net to get a copy of this message
Regarding "php at keith tyler dot com" note about global scope - the $filename variable is clearly not actually in global scope. It is in the scope that phpunit runs the unit tests, which is local scope. Your "fix" simply creates a global variable called "filename" with the contents of the *local* variable "filename". To illustrate: file1.php: <?php class Foo { static public function bar() { global $filename; return $filename; } } ?> run.php: <?php $filename = 'mia'; include('file1.php'); assert( null === Foo::bar() ); ?> In the "run.php" file, Foo::bar() will return NULL, because $filename is in local scope. ---- Server IP: 69.147.83.197 Probable Submitter: 203.110.140.233 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- https://master.php.net/note/edit/101385 Del: integrated -- https://master.php.net/note/delete/101385/integrated Del: useless -- https://master.php.net/note/delete/101385/useless Del: bad code -- https://master.php.net/note/delete/101385/bad+code Del: spam -- https://master.php.net/note/delete/101385/spam Del: non-english -- https://master.php.net/note/delete/101385/non-english Del: in docs -- https://master.php.net/note/delete/101385/in+docs Del: other reasons-- https://master.php.net/note/delete/101385 Reject -- https://master.php.net/note/reject/101385 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174894) next »