note 60243 deleted from language.variables.scope by tularis

From: Date: Sat, 31 Dec 2005 09:35:31 +0000
Subject: note 60243 deleted from language.variables.scope by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101034@lists.php.net to get a copy of this message
Note Submitter: windandwaves ---- Consider the files and their content below: --index.php <?php include_once("inc2.php"); include_once("inc1.php"); goer(); echo "var 1: ".$dd_myvar1.'<br>'; echo "var 2: ".$dd_myvar2.'<br>'; echo "var 3: ".$dd_myvar3.'<br>'; ?> --inc1.php: <?php $dd_myvar1 = "inc1"; ?> --inc2.php: <?php $dd_myvar2 = "inc2"; function goer() { include_once("inc3.php"); } ?> --inc3.php: <?php $dd_myvar3 = "inc3"; function roer() { die("ran roer"); } ?> opening index.php in your browser will produce: var 1: inc1 var 2: inc2 var 3: It took me a while to work out why var 3 was not showing. From this simplified example it is obvious that because the include statement in inc2.php is in a function, it will only apply to that function (taking the include function out of the function will show var3). Now, if we add roer(); as the last line to index.php and then open it in the browser then you will see: inc var 1: inc1 inc var 2: inc2 inc var 3: ran roer This may be confusing. While the variables loaded from goer could not be seen, the function loaded was available in index.php.

« previous php.notes (#101034) next »