note 45877 added to function.include

From: Date: Wed, 22 Sep 2004 11:29:39 +0000
Subject: note 45877 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-77146@lists.php.net to get a copy of this message
I had a problem with globals not working proper in combination with include(). <? // First script. ]----------------------------------- // The second script will work fine if you would include here. // // include("second_script.php"); function IncludeRecursive() { // Here the second script will not work as expected because include is used in a function and thus all "global" variables of the second script are treated as local to the IncludeRecusive() function of the first script. // ... include("second_script.php"); // ... } ?> <? // Second script. ]----------------------------------- // That's why you have to use $GLOBALS["strGlobalVariable"] here. // $strGlobalVariable = "The true meaning lies in your head, and does not come out when said. - BoonHead"; function SayIt() { global $strGlobalVariable; echo($strGlobalVariable); } ?> dUh|BoonHead.nl ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45877 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45877&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45877&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77146) next »