RE: [PHP] Require() vs Include()
| From: | Maxim Maletsky | Date: | Wed, 15 Nov 2000 02:07:21 +0000 |
| Subject: | RE: [PHP] Require() vs Include() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-25321@lists.php.net to get a copy of this message | ||
not since the version 4.0.2 as Zeev says...
now require() and include() are *exactly* the same except that require()
exits the script prematurely on a failure. Everything else is identic.
Cheers!
-----Original Message-----
From: Tim Ward [mailto:tim.ward@stivesdirect.com]
Sent: Tuesday, November 14, 2000 9:01 PM
To: Maxim Maletsky
Subject: RE: [PHP] Require() vs Include()
if you're in a loop require will only run the first time, hence use it for
including external functions.
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net]
> Sent: 14 November 2000 04:52
> To: 'Lawrence.Sheed@dfait-maeci.gc.ca'
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Require() vs Include()
>
>
> OK, then.
>
> what is the reason require() exists?
>
>
> If it works the exactly same way as include() except that
> include can be
> more flexible why would we use require() then?
>
> Any performance issues?
> usability?
> security?
>
> Thanks Lawrence,
>
>
> -----Original Message-----
> From: Lawrence.Sheed@dfait-maeci.gc.ca
> [mailto:Lawrence.Sheed@dfait-maeci.gc.ca]
> Sent: Tuesday, November 14, 2000 1:37 PM
> To: Maxim Maletsky; Lawrence.Sheed@dfait-maeci.gc.ca
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Require() vs Include()
>
>
> Ok,
>
> Require will always add in the file even if its not executed.
>
>
> Eg
>
> if (isset($includeme)) {
> require ("xxx.php");
> }
>
> require will be included in the file parsed by php
>
> but the following will not get included in the file if
> $includeme is not
> set.
>
> if (isset($includeme)) {
> include ("xxx.php");
> }
>
> An important note about how this works is that when a file is
> include()ed or
> require()ed, parsing drops out of PHP mode and into HTML mode at the
> beginning of the target file, and resumes PHP mode again at
> the end. For
> this reason, any code inside the target file which should be
> executed as PHP
> code must be enclosed within valid PHP start and end tags.
>
> Unlike include(), require() will always read in the target
> file, even if the
> line it's on never executes. If you want to conditionally
> include a file,
> use include(). The conditional statement won't affect the require().
> However, if the line on which the require() occurs is not
> executed, neither
> will any of the code in the target file be executed.
>
>
> The manual is actually pretty good on this topic imho.
>
> http://www.php.net/manual/function.require.php
>
>
> -----Original Message-----
> From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net]
> Sent: November 14, 2000 12:34 PM
> To: 'Lawrence.Sheed@dfait-maeci.gc.ca'
> Cc: 'PHP General List. (E-mail)'
> Subject: RE: [PHP] Require() vs Include()
>
>
> Well,
> with include() if an included file does not exists it WILL fail.
>
> so where's the difference?
>
> -----Original Message-----
> From: Lawrence.Sheed@dfait-maeci.gc.ca
> [mailto:Lawrence.Sheed@dfait-maeci.gc.ca]
> Sent: Tuesday, November 14, 2000 1:26 PM
> To: Maxim Maletsky
> Subject: RE: [PHP] Require() vs Include()
>
>
> include won't fail out if the includes not there, but require will.
>
> If you have something that *has* to be in there, then require
> is used, if
> something could be optional - eg a generated header or
> something than might
> be or might not be there at a given time, use include.
>
>
>
> -----Original Message-----
> From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net]
> Sent: November 14, 2000 12:21 PM
> To: 'PHP General List. (E-mail)'
> Subject: [PHP] Require() vs Include()
>
>
> Hi,
> A tiny question:
>
> why to use require() when include() works just as well and
> even better when
> there are some conditions like if{} ?
>
> I ask it because although I read many articles on this issue
> I found no
> reason for myself to use require() instead of include() and I
> have driven
> some huge projects in PHP.
>
> Why do I see these hardcore PHP gurus writing PHPLIB, mySQLadmin and
> examples in their articles using require() where include()
> would fit just as
> perfect?
>
> WHERE THE TRIIIICK?
>
> It escapes from me ...
>
> Thanks.
>
> Maxim Maletsky - maxim@j-door.com <mailto:maxim@j-door.comðÄÙ]ép¸…
> Î<>
> Webmaster, J-Door.com / J@pan Inc.
> LINC Media, Inc.
> TEL: 03-3499-2175 x 1271
> FAX: 03-3499-3109
>
> http://www.j-door.com
> <http://www.j-door.com/>
> http://www.japaninc.net
> <http://www.japaninc.net/>
> http://www.lincmedia.co.jp
> <http://www.lincmedia.co.jp/>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>