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

From: Date: Tue, 14 Nov 2000 05:22:41 +0000
Subject: RE: [PHP] Require() vs Include()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25138@lists.php.net to get a copy of this message
How can you not allow it to fail? if you go to require('/tmp/the_file_that_does_not_exist'), how do you handle that successfully and still finish the script? This is the claim that Joe and I's co-worker claimed. Above was my example back to him. That was the end of the conversation. I do understand what you are saying, but it is misleading when you say it is not allowed to fail -- it implies (apparently to our co-worker) that even if a file doesn't exist, somehow his code was magically going to work anyway. This seems to be what is probably most misunderstood. -jeremy brand http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more --------------------------------------------------------------------- We cannot do everything at once, but we can do something at once. -- Calvin Coolidge On Tue, 14 Nov 2000, Andi Gutmans wrote: > Date: Tue, 14 Nov 2000 07:16:22 +0200 > From: Andi Gutmans <andi@zend.com> > To: Mark Peoples <gascsd@gascairlines.com>, "'PHP General List. (E-mail)'" <php-general@lists.php.net> > Subject: RE: [PHP] Require() vs Include() > > In the latest versions of PHP 4.0 (I think since 4.0.2) require() and > include() behave exactly the same *except* that a require() is not allowed > to fail. So feel free to use any of these two, they are the same speed. The > implementation of require() used to be different but both for consistency > reasons and due to the fact that the old require() wasn't faster than the > include() as it was supposed to be we chose consistency. > > Andi > > At 09:55 PM 11/13/00 -0700, Mark Peoples wrote: > >Hi Maxim, > > Suppose you have this: > > > >--file1.php-- > ><?php print("\nin file1.php"); ?> > > > >--file2.php-- > ><?php print("\nin file2.php"); ?> > > > > > >Now, suppose you want to include certain files, based on conditions: > > > >--test.php-- > >if($myCatVioletHasBlackFur == "no") > > require(file1.php); > >if($myCatVioletHasBlackFur == "yes") > > include(file2.php); > > > >Well, my cat, Violet <g>, has black fur, so the 2nd condition is valid, the > >1st is false. However, require() is executed regardless, so, the output of > >test.php is: > > > >in file1.php > >in file2.php > > > > > >So, what if I change test.php to: > > > >--test.php-- > >if($myCatVioletHasBlackFur == "no") > > include(file1.php); > >if($myCatVioletHasBlackFur == "yes") > > include(file2.php); > > > > > >Well, Violet still has black fur, so, the output is: > > > >in file2.php > > > > > >Hope this helps. =) > > > > > >marco > > > > > >-----Original Message----- > >From: Maxim Maletsky [mailto:maxim.maletsky@japaninc.net] > >Sent: Monday, November 13, 2000 9: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\Îr > >Ä6»º‰þÍêåÐ > > >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 > > --- > Andi Gutmans <andi@zend.com> > http://www.zend.com/ > > -- > 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 (#25138) next »