ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

Difference between include() and include_once() in PHP

function.php

function foo(){ 
echo 'some code'; 

?>
Global.php

include('FUNCTIONS.PHP');
foo();
?>
Header.php
include('FUNCTIONS.PHP');
include('GLOBALS.PHP');
foo();
?>

now if you try to open HEADER.PHP you will get an error becauseglobal.php includes function.php already. you will get an error saying that function foo() was already declared in global.php, and i also included inHeader.php - which means i have included function.php two times. 

so to be sure i only include function.php only ONE time, i should use the include_once() function, so my Header.php should look like this: 

Header.php
include_once('FUNCTIONS.PHP');
include('GLOBALS.PHP');
?>

now when i open Header.php, i will not get an error anymore because PHP knows to include the file function.php only ONCE  

No comments:

Post a Comment