| | |
the difference between include and require
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
•
•
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
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
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!
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!
•
•
Join Date: Jun 2005
Posts: 60
Reputation:
Solved Threads: 5
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.
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.
![]() |
Similar Threads
- Simple ASP.Net Login Page using C# (C#)
- random page crashes in php (PHP)
- what's with gcc? (C++)
- Listing files in a folder (C++)
- Execution time (C)
- Errors writing a vector to a file (C++)
- asp.net tutorial (ASP)
- PHP Beginner Here (PHP)
- Sorting arrays of pointers with function? (C)
Other Threads in the PHP Forum
- Previous Thread: PHP Programmer needed (CMS)
- Next Thread: Help with querys please
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube





