note 56269 added to function.include-once
| From: | php-general at lists dot php dot net | Date: | Mon, 29 Aug 2005 08:52:36 +0000 |
| Subject: | note 56269 added to function.include-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94331@lists.php.net to get a copy of this message | ||
Dealing with function redefinitions
include_once and require_once are very useful if you have a library of common functions. If you try
to override with - that is define - an identically named local function however, PHP will halt
noting that it cannot redeclare functions. You can allow for this by bracketing (within the include
file):
function myUsefulFunc($arg1, $arg2) {
... }
with
if (!function_exists('myUsefulFunc')) {
function myUsefulFunc($arg1, $arg2) {
... }}
Top level functions (ie. those not defined within other functions or dependent on code running) in
the local file are always parsed first, so http://php.net/function_exists within the
included/required file is safe - it doesn't matter where the include statements are in the
local code.
Csaba Gabor from Vienna
----
Manual Page -- http://www.php.net/manual/en/function.include-once.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56269
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56269&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56269&report=yes
Search -- http://master.php.net/manage/user-notes.php