note 56189 deleted from function.include by aidan
| From: | aidan@php.net | Date: | Sat, 15 Apr 2006 16:33:55 +0000 |
| Subject: | note 56189 deleted from function.include by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108160@lists.php.net to get a copy of this message | ||
Note Submitter: ystgermain at canac dot com
----
When many files need to include the same file then you might end up with an error saying
class/function already defined... To avoid this, you can use the following trick:
Add the following in your include file (NOTE: give a unique defined name for each include file):
if (!defined("GLOBALS_DEFINED"))
{
define("GLOBALS_DEFINED", 1);
//... Place code and definitions here
} // End of if (!defined(...
For example:
-----------------------
globals.php
<?php
if (!defined("GLOBALS_DEFINED"))
{
define("GLOBALS_DEFINED", 1);
class CMessages
{
//... Place code here
} // End of class definition
} // End of if (!defined(...
?>
-----------------------
test.php
<?php
include("globals.php");
//... Place Code here
-----------------------
main.php
<?php
include("test.php");
include("globals.php");
//... Place Code here
?>
-----------------------