note 77803 added to function.function-exists
| From: | White-Gandalf at osu1 dot php dot net | Date: | Thu, 13 Sep 2007 14:26:19 +0000 |
| Subject: | note 77803 added to function.function-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130467@lists.php.net to get a copy of this message | ||
I stumbled over the same problem as "eddiec" (users not able or not willing to use
"_once"-suffixes).
A possible alternative explanation for the behavior:
If a file is included, it is possibly parsed every include-time.(?)
While parsing, every function in global scope is tried to register. THIS gets wrong, when multiple
times included, and it produces an error.
If functions are defined within block scopes, their registration seems to be delayed until execution
of such a block. Thus, not the function "function_exists" functions wrong, but simply the
philosophy of the interpreter produces such results.
Thus, the same effect can be achieved by simply putting block braces around the contents of an
include_once file:
if (function_exists('function_in_question')) return;
{
function function_in_question(...)
{
...
}
...other stuff
}
...which is equivalent to...
if (!function_exists('function_in_question'))
{
function function_in_question(...)
{
...
}
...other stuff
}
----
Server IP: 212.124.37.9
Probable Submitter: 80.152.169.235
----
Manual Page -- http://www.php.net/manual/en/function.function-exists.php
Edit -- https://master.php.net/note/edit/77803
Del: integrated -- https://master.php.net/note/delete/77803/integrated
Del: useless -- https://master.php.net/note/delete/77803/useless
Del: bad code -- https://master.php.net/note/delete/77803/bad+code
Del: spam -- https://master.php.net/note/delete/77803/spam
Del: non-english -- https://master.php.net/note/delete/77803/non-english
Del: in docs -- https://master.php.net/note/delete/77803/in+docs
Del: other reasons-- https://master.php.net/note/delete/77803
Reject -- https://master.php.net/note/reject/77803
Search -- https://master.php.net/manage/user-notes.php