RE: [PHP] Require() vs Include()

From: Date: Tue, 14 Nov 2000 05:18:10 +0000
Subject: RE: [PHP] Require() vs Include()
Groups: php.general 
Request: Send a blank email to php-general+get-25135@lists.php.net to get a copy of this message
As I've said before, the main difference (for moi) is that I use require when (to paraphrase a delivery firm advert), it absolutely positively has to be in there. I use include when it can fail so <?php require "perfect_php_code.php"; @include "crappy_header_stuff_from_some_dork.php"; ?> Will fail if perfect_php_code.php isn't there, but continue if crappy_header_stuff_from_some_dork.php is there ;) Another point: <?php for ($i=1;$i<5;$i++) { require "file". $i . ".php"; } ?> Will not work, because of the way require differs from include but <?php for ($i=1;$i<5;$i++) { include "file". $i . ".php"; } ?> Will work. You can think of include as a souped up require. Joe, I'm interested in what problems require was giving you. I've found it to be problem free. I use require ($DOCUMENT_ROOT . "/phpstuff/xxx.php"); style stuff a lot. -----Original Message----- From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net] Sent: November 14, 2000 01:13 PM To: 'Lars Torben Wilson' Cc: Lawrence.Sheed@dfait-maeci.gc.ca; php-general@lists.php.net Subject: RE: [PHP] Require() vs Include() Does that mean that we can freely write to the whole mailing list (the whole world) DO NEVER USE REQUIRE() SINCE THERE'S INCLUDE() WHICH IS 100.00% BETTER ? I mean, in something require() is still being good, isn't it? Cheers, Maxim Maletsky -----Original Message----- From: Lars Torben Wilson [mailto:torben@php.net] Sent: Tuesday, November 14, 2000 3:06 PM To: Maxim Maletsky Cc: Lawrence.Sheed@dfait-maeci.gc.ca; php-general@lists.php.net Subject: RE: [PHP] Require() vs Include() Maxim Maletsky writes: > 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, In PHP 3, it was quite a bit faster than include(). There were other semantic differences between the two as well, such as return values etc. Performance appears to now be pretty much the same; you can return values with include() now, and so forth and so on. BTW, require() will fail in a completely different way from include() when it can't find the target file. include() will simply return a false value, whereas require() will spit out a great big 'Fatal error' and halt script execution. -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+ -- 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 -- 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

« previous php.general (#25135) next »