note 26404 added to function.require-once

From: Date: Tue, 29 Oct 2002 22:36:05 +0000
Subject: note 26404 added to function.require-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-38720@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.require-once.php http://master.php.net/manage/user-notes.php?action=edit+26404 http://master.php.net/manage/user-notes.php?action=delete+26404 http://master.php.net/manage/user-notes.php?action=reject+26404

« previous php.notes (#38720) next »