note 77802 added to function.function-exists

From: Date: Thu, 13 Sep 2007 14:25:21 +0000
Subject: note 77802 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-130466@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/77802 Del: integrated -- https://master.php.net/note/delete/77802/integrated Del: useless -- https://master.php.net/note/delete/77802/useless Del: bad code -- https://master.php.net/note/delete/77802/bad+code Del: spam -- https://master.php.net/note/delete/77802/spam Del: non-english -- https://master.php.net/note/delete/77802/non-english Del: in docs -- https://master.php.net/note/delete/77802/in+docs Del: other reasons-- https://master.php.net/note/delete/77802 Reject -- https://master.php.net/note/reject/77802 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130466) next »