★ wanayoo — archive 1999 http://uk.php.net/manual/ro/function.require.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<returninclude>
view the version of this page
Last updated: Fri, 16 Jul 2004

require()

The require() statement includes and evaluates the specific file.

require() includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for include().

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.

Exemplu 11-2. Basic require() examples

<?php

require 'prepend.php';

require
$somefile;

require (
'somefile.txt');

?>

See the include() documentation for more examples.

Notã: 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.

Notã: Because this is a language construct and not a function, it cannot be called using variable functions

Avertisment

Windows versions of PHP prior to PHP 4.3 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

See also include(), require_once(), include_once(), eval(), file(), readfile(), virtual() and include_path.



add a note add a note User Contributed Notes
require
jaisen - at - jmathai - dot - com
12-Mar-2004 08:10
NOTE: This function changed how it worked.  In PHP 3 this behaved very differently than it does on PHP 4.  Require used to include and parse the file regardless where the require line was positioned.

For example (PHP3):

<?php
 
if(false){ require 'file_does_not_exist.php'; }
?>

That code throw a fatal exception even though it's in a conditional block which evaluates to false.  In PHP 4 the file is never included or parsed, so no exception is thrown.

For example (PHP4)
<?php
 
if(false){ require '1_file_does_not_exists.php'; }
  require
'2_file_does_not_exists.php';
?>

Stops execution of the script on trying to require the 2nd file...by bypasses the first require.

--JM

<returninclude>
 Last updated: Fri, 16 Jul 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Kewlio.net Limited
Last updated: Fri Nov 5 13:37:53 2004 GMT