note 89861 added to function.function-exists
| From: | HayleyWatson at osu1 dot php dot net | Date: | Thu, 26 Mar 2009 09:54:54 +0000 |
| Subject: | note 89861 added to function.function-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152464@lists.php.net to get a copy of this message | ||
Regarding neelam_ab2003 at yahoo dot co dot in's comment about nested functions.
Nested functions _do_ exist once the functions that contain them have been called and the code that
defines them is evaluated; until then, they don't.
<?php
function A(){}
function B(){
function C(){
function D(){}
}
}
IsFunctionExist('A');
IsFunctionExist('B');
IsFunctionExist('C');
IsFunctionExist('D');
B();
echo '<br>';
IsFunctionExist('A');
IsFunctionExist('B');
IsFunctionExist('C');
IsFunctionExist('D');
C();
echo '<br>';
IsFunctionExist('A');
IsFunctionExist('B');
IsFunctionExist('C');
IsFunctionExist('D');
function IsFunctionExist($funcName){
echo function_exists($funcName)?" $funcName exists <br>":" $funcName
doesn't exist <br>";
}
/*O U T P U T
A exists
B exists
C doesn't exist
D doesn't exist
A exists
B exists
C exists
D doesn't exist
A exists
B exists
C exists
D exists
*/
?>
This makes sense for other functions that are defined at runtime.
<?php
if(true)
{
function A(){}
}
else
{
function B(){}
}
IsFunctionExist('A');
IsFunctionExist('B');
/*
A exists
B doesn't exist
*/
?>
----
Server IP: 202.89.58.1
Probable Submitter: 114.134.161.9
----
Manual Page -- http://www.php.net/manual/en/function.function-exists.php
Edit -- https://master.php.net/note/edit/89861
Del: integrated -- https://master.php.net/note/delete/89861/integrated
Del: useless -- https://master.php.net/note/delete/89861/useless
Del: bad code -- https://master.php.net/note/delete/89861/bad+code
Del: spam -- https://master.php.net/note/delete/89861/spam
Del: non-english -- https://master.php.net/note/delete/89861/non-english
Del: in docs -- https://master.php.net/note/delete/89861/in+docs
Del: other reasons-- https://master.php.net/note/delete/89861
Reject -- https://master.php.net/note/reject/89861
Search -- https://master.php.net/manage/user-notes.php