News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

require vs. require_once function

Started by reznorsoft, August 18, 2004, 10:43:07 AM

Previous topic - Next topic

reznorsoft

what is the difference between the require and require_once function  ???
are there any benefits one has over the other .. and in what circumstance would you opt to use .. well, one rather than the other?

Cypher7

something I found via Google...

http://ie.php.net/require_once

I haven't a clue what it means... but might be of use to you!!

Grudge

If, for example you used require to output your forum header, everytime you "require'd" that file the header would be output. If you use require_once, every time you call it it knows the file has already been included so won't do anything. require_once is generally more efficient as it stops parsing the same file twice (or more times)
I'm only a half geek really...

Tomer

Yes sometimes if you get a PHP error, try switching to _once and it may solve the problem.

Christian Land

create the following 3 files and execute 1.php and 2.php ::)

1.php:
<?php

require(
'rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');
require('rtfm.php');

?>


2.php:
<?php

require_once(
'rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');
require_once('rtfm.php');

?>


rtfm.php:

<?php

echo
'reading manuals = knowledge<br />';

?>

reznorsoft

thanks for everyone's replies ..

Quote from: SnowCrash on August 18, 2004, 12:06:01 PM
create the following 3 files and execute 1.php and 2.php ::)
and thanks for the visual demo   ;D

Advertisement: