RE: [PHP] require

From: Date: Fri, 27 Oct 2000 22:59:42 +0000
Subject: RE: [PHP] require
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22389@lists.php.net to get a copy of this message
"Jay Greenspan" ... (....) > > However, in writing an example like the following, require did > include all five files... > > $i = 0 Peeeeeeeeeeeeeep!!!!! Parse error! > 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; > ?> If you're using $i in both the main page and both files... doesn't it crash??? > 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. I use 3.0.9, it wouldn't be matter. As far as i know, if you try to require the SAME file several times, it just includes it one time... not as include: require "file.php"; require "file.php"; require "file.php"; require "file.php"; require "file.php"; require "file.php"; would do the same as include "file.php"; Require SHOULD (computers sometimes just don't obbey you) ignore the second, thinrd and so on calls.

« previous php.general (#22389) next »