master82 Posted August 30, 2006 Share Posted August 30, 2006 Are they the same or is there a difference?If there is a difference, can somebody please tell me what that would be......Thanks in advance ;D Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 30, 2006 Share Posted August 30, 2006 From the manual:require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 30, 2006 Share Posted August 30, 2006 include will include your file whenever the flow of code calls it.require will include your file regardless...eg.if ($string == 'yep'){ include('file.php);}will only include your file if $string is 'yep'.if ($string == 'yep'){ require('file.php);}will include it no matter what $string is. Quote Link to comment Share on other sites More sharing options...
Jenk Posted August 30, 2006 Share Posted August 30, 2006 [quote author=ToonMariner link=topic=106246.msg424672#msg424672 date=1156945987]include will include your file whenever the flow of code calls it.require will include your file regardless...eg.if ($string == 'yep'){ include('file.php);}will only include your file if $string is 'yep'.if ($string == 'yep'){ require('file.php);}will include it no matter what $string is.[/quote]Incorrect. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 30, 2006 Share Posted August 30, 2006 from the manualNote: Prior to PHP 4.0.2, the following applies: require() will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect 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. Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once. apology accepted ;) Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 30, 2006 Share Posted August 30, 2006 well, yes there is a difference:1. when using include, script continuous running anyway, for example: you have a header included, and this header.php files has been deleted, script will display averything but header... 2. when using require script will stop running if there is any error, in my example it won't display enything but an error Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 30, 2006 Share Posted August 30, 2006 [quote author=ToonMariner link=topic=106246.msg424672#msg424672 date=1156945987]include will include your file whenever the flow of code calls it.require will include your file regardless...eg.if ($string == 'yep'){ include('file.php);}will only include your file if $string is 'yep'.if ($string == 'yep'){ require('file.php);}will include it no matter what $string is.[/quote]this is not accurate at all. go back and read GingerRobot's response. she has the right of it, and imagine that: she actually got the answer from the manual! why can't more people do that... lol ;-) Quote Link to comment Share on other sites More sharing options...
Jenk Posted August 30, 2006 Share Posted August 30, 2006 [quote author=ToonMariner link=topic=106246.msg424675#msg424675 date=1156946138]from the manualNote: Prior to PHP 4.0.2, the following applies: require() will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect 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. Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once. apology accepted ;)[/quote]No apology given. Take note of "prior to 4.0.2"Any host still running < 4.0.2 is a poor host ;) Your apology accepted.Also note that the code will not be executed even in < 4.0.2. require() just tries to read the file. Another apology accepted. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 30, 2006 Share Posted August 30, 2006 LOLSorry I have ben around for too long!!!I learnt that many moons ago - and its stuck. But hey you learn new stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.