require
| From: | Jay Greenspan | Date: | Fri, 27 Oct 2000 13:01:44 +0000 |
| Subject: | require | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-22332@lists.php.net to get a copy of this message | ||
Have I read the manual entry? Oh, yes.
I'm doing some writing on PHP and am attempting
to show an example of when require will not work
as one would like.
The manual says:
"This means that you can't put a require() statement inside
of a loop structure and expect it to include the contents
of a different file on each iteration."
However, in writing an example like the following, require did
include all five files...
$i = 0
while ($i < 5)
{
$filename = "myfile_$i.php"
require $filename;
$i++;
}
Someone else suggested to me that the contents of a require will not
be re-evaluated within a loop. However, the following two files printed all
numbers from 0-10.
#file1
<?
$i =0;
while ($i <=10)
{
require "file2.php";
$i++
}
?>
#file2.php
<?
echo $i;
?>
So I guess I have 2 questions:
First, can someone give me an example, using PHP 4.0.2, where
require behaves differently from include?
Secondly, I'm wondering if the differences between include and require
are a big issue for many of you. I put my includes at the top of the page,
one at the bottom, and I'm set.
Thanks much,
jay