note 73120 added to function.function-exists

From: Date: Fri, 09 Feb 2007 17:58:38 +0000
Subject: note 73120 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-123180@lists.php.net to get a copy of this message
Note that function_exists will return TRUE in the following situation, presumably because the function "testfunc" was defined when the script was PARSED/ITERPRETED, before the function_exists call was made at RUNTIME: <? if (function_exists('testfunc')) return; function testfunc() { } ?> So, this construction is not useful for preventing testfunc from being multiply defined if the script is muliply included or required. However, the following construction DOES work to prevent multiple defines of testfunc: <? if (!function_exists('testfunc')) { function testfunc() { } } ?> CONTRAST this with similar uses of defined() which is completely runtime evaluated. These both work: <? if (defined('testfunc_defined')) return; define('testfunc_defined', 1); function testfunc() { } ?> AND... <? if (!defined('testfunc_defined')) { define('testfunc_defined', 1); function testfunc() { } } ---- Server IP: 64.71.164.2 Probable Submitter: 69.18.45.18 ---- Manual Page -- http://www.php.net/manual/en/function.function-exists.php Edit -- https://master.php.net/note/edit/73120 Del: integrated -- https://master.php.net/note/delete/73120/integrated Del: useless -- https://master.php.net/note/delete/73120/useless Del: bad code -- https://master.php.net/note/delete/73120/bad+code Del: spam -- https://master.php.net/note/delete/73120/spam Del: non-english -- https://master.php.net/note/delete/73120/non-english Del: in docs -- https://master.php.net/note/delete/73120/in+docs Del: other reasons-- https://master.php.net/note/delete/73120 Reject -- https://master.php.net/note/reject/73120 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123180) next »