note 26404 deleted from function.require-once by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 00:45:40 +0000 |
| Subject: | note 26404 deleted from function.require-once by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59825@lists.php.net to get a copy of this message | ||
Note Submitter: ewhite AT stsci.edu
----
Be warned ... require_once is not 'context sensitive'.
The specific situation I am talking about, is using it within a class (and in particular, within a
class instantiation procedure.) Therefore, something like this following:
class MyClass
{
function MyClass
{
require_once("file.php");
// Do more stuff, including setting variables based upon stuff in the required file.
}
}
The first time you instantiate this class, everything works fine. And the variables being set based
upon information in the required file are perfect.
However, you go to instantiate another copy of this class, and problems arise. Even though it is a
different instantiation, and in a different 'namespace', require_once will NOT work. It
thinks it has already included the file (which it did, in another class copy).
Therefore your variable setting starts failing.
In this case, you need to use require instead to allow it to be re-read each time over again with
each new instantiation.