Re: require v. includes

From: Date: Thu, 07 Mar 2002 18:17:00 +0000
Subject: Re: require v. includes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-87656@lists.php.net to get a copy of this message
Joshua E Minnie wrote:
I was just wondering if anyone could tell me when would be the time to choose require(), require_once(), or include(). I know a little bit about using each one, but I am just not sure if there is one that is better than the other in certain situations.
For all intents and purposes there's no real difference between the two. 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. require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. Michael Kimsal http://www.phphelpdesk.com Taking the ? out of <?php 734-480-9961

« previous php.general (#87656) next »