note 11713 added to require
| From: | omnivore at eol dot ca | Date: | Sat, 03 Mar 2001 16:51:42 +0000 |
| Subject: | note 11713 added to require | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11815@lists.php.net to get a copy of this message | ||
I have a file, test1.php:
<?
require("testInclude.php");
include("test2.php");
?>
test2.php looks like this:
<?
require("testInclude.php");
echo "done";
?>
If testInclude.php includes a function definition:
<?
function nothing(){
#misc code
}
?>
Then the operation fails with the message:
Fatal error: Cannot redeclare nothing() in Unknown on line 3
Indicating that require() is called repeatedly if the calls are on separate lines. In practical
terms, this means I have to include a define() in the included file which is a flag to indicate that
the include has happened already.
Each page that includes the testInclude.php page then has to check if this value is defined and use
a conditional include() instead of require()... The ideal solution would be a php command that would
include() the file only if it had not previously been included.
I thought that this is what require did, but it does not. Given the similarities between require()
and include(), would this not be a good direction to take require() in?
http://www.php.net/manual/en/function.require.php