the difference between include and require

Reply

Join Date: Jun 2005
Posts: 92
Reputation: michael123 is an unknown quantity at this point 
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

the difference between include and require

 
0
  #1
Jun 16th, 2005
What's the difference between "include", "include_once", "require", "require_once"?

thanks.
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 781
Reputation: Zachery has a spectacular aura about Zachery has a spectacular aura about 
Solved Threads: 21
Team Colleague
Zachery's Avatar
Zachery Zachery is offline Offline
The Geek Father

Re: the difference between include and require

 
0
  #2
Jun 16th, 2005
Originally Posted by php.net
The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, 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. Be warned that parse error in required file doesn't cause processing halting in PHP versions prior to PHP 4.3.5. Since this version, it does.

That cover it?
Firefox: no, its not the end all solution, it has its own issues and in time it will be just as insecure as IE, when its hit Firefox 6, if it makes it that far. Oh, and AOL pays for it, incase you didn't know.

Microsoft & Windows: If you hate it so much, move to linux, or bsd, or anything else, stop complaning and move on.
Good starting places: Gentoo Novell SUSE Fedora Core Apple
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: the difference between include and require

 
0
  #3
Jun 16th, 2005
Yep, the documentation at www.php.net makes it pretty clear. If you code PHP, you probably want to keep php.net open in a browser at all times! Very nice documentation, and the comments can be a lifesaver---when they are accurate anyway!

In my applications, and I have to think in most people's, my includes are not optional. And of course, I only want an include file included once. So I almost always use require_once().

I was a hard-core ASP developer for many years. It took me all of 2 weeks to become a PHP convert. Features like require_once() and the ability to conditionally include files are part of what makes PHP so sweet when compared to ASP.

Enjoy the journey!
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 60
Reputation: pclfw is an unknown quantity at this point 
Solved Threads: 5
pclfw pclfw is offline Offline
Junior Poster in Training

Re: the difference between include and require

 
0
  #4
Jun 25th, 2005
Don't forget that using 'REQUIRE' will ensure that the file is included as the parser looks for 'REQUIRE's prior to parseing the file. Thus 'REQUIRE'd files are allways included. However the 'INCLUDE' may be avoided via programming.

i.e.
$language = 'english';

if $language = "french" {
include_once '.\french_file.php';
}
else {
include_once '.\not_french_file.php';
}
In this instance the file to be included will depend on the status of the variable '$french'.

If this was written as -
if $language = "french" {
require_once '.\french_file.php'
}
else {
require_once '.\not_french_file.php'
}
then BOTH files would be included, irrespective of the value of $language.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC