Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: php include()



Further on this. Now the only difference between include and require is regarding how the script acts in case of failure. With require the script dies, with include it gives and error and continues.

Also, reading this thread and as has been pointed out it is better to use single quotes where possible.
e.g. require("navigation.inc"); would be better as require('navigation.inc');


This is useful too
require('./nav.php');
as it will only look in the same directory which is usually the behaviour you want
rather than
require('nav.php') which looks inside the directories specified by the include path in the config file which may not be the behaviour you want.


Gary

On 30 Jun 2004, at 11:29 am, Timothy Binder wrote:

On Jun 29, 2004, at 9:39 PM, Gary Minato wrote:

I use the php require() function when the same content must be included
on every page, eg


<?php require("navigation.inc"); ?>

I use include() if I need to provide options when using if, else or
other statements, eg

<?php
$request="boy";
if ($request=='boy') {
include("boy.php");
}
else {
include("girl.php");
}
?>

Note that require & include are now almost identical, as of PHP 4.0.2, and it doesn't seem necessary to make this distinction in your case. (Previously, require() was evaluated, even if the line wasn't executed.)


From <http://us2.php.net/require>

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.

Other useful commands are require_once & include_once, which make sure the files are only included once -- useful if you're including a block of functions & another included file might try to include them as well.


Hope these help,
Tim
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.


References: 
 >php include() (From: John Crockford <email@hidden>)
 >Re: php include() (From: Gary Minato <email@hidden>)
 >Re: php include() (From: Timothy Binder <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.