note 35242 added to function.include
| From: | peter at rack1 dot php dot net | Date: | Mon, 25 Aug 2003 09:10:24 +0000 |
| Subject: | note 35242 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55025@lists.php.net to get a copy of this message | ||
In addition to (dnac at NOSPAM dot linuxmail dot org) on 26-Jan-2003:
When including a file from within a function or a class method, normally global variables from the
include-file stay in the scope of that function. When using the $GLOBALS array in the include file
the variables are accessible from your php code. It is quite obvious, but it's worth a note.
---------test.php
<?
class Test {
function inc() {
require("test3.inc");
}
}
$objTest = new Test();
$objTest->inc();
echo $strTest;
?>
------------------
----------test3.inc
<?
$GLOBALS['strTest'] = "hi";
?>
------------------
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35242
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35242&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35242&report=yes