Ask a Question related to PHP Notes, Design and Development.
-
dshearin@excite.com #1
note 33827 added to function.function-exists
This can be used to conditionally define a user function. In this sense, it can act as a sort of inline include_once().
For example, suppose you have a function A that calls function B. B is only used inside function A and is never called from anywhere else in the script. It's logical (and perfectly legal in PHP) to define B inside of A's definition, like so:
function A($inputArray)
{
if (!function_exists('B'))
{
function B($item)
{
// Do something with $item
// and return result
return $result;
}
}
foreach ($inputArray as $nextItem) $outputArray[] = B($nextItem);
return $outputArray;
}
Without the function_exists test, you would get a fatal error the second time you called A, as PHP would think you were trying to redefine B (not legal in PHP). The placement of the test is also important. Since the if block is executed sequentially, like any other block of code, it must come before any call to the function defined within.
----
Manual Page -- [url]http://www.php.net/manual/en/function.function-exists.php[/url]
Edit Note -- [url]http://master.php.net/manage/user-notes.php?action=edit+33827[/url]
Delete Note -- [url]http://master.php.net/manage/user-notes.php?action=delete+33827&report=yes[/url]
Reject Note -- [url]http://master.php.net/manage/user-notes.php?action=reject+33827&report=yes[/url]
dshearin@excite.com Guest
-
note 33727 added to function.is-int
To Logan: There's also a simple non-regexp way to convert a (form) value into an integer if it consists of numbers only - although with a trap... -
note 33714 added to function.register-tick-function
please can anyone help me to discover if this function can be used to make a chat ---- Manual Page --... -
note 33689 added to function.next
i was just looking around and saw this. i'd just like to say "huh" and be on my merry way. ok buh-bi. merry meet, rose love ---- Manual Page --... -
note 33621 added to function.ftp-put
Is there a way to not overwrite existing files? ---- Manual Page -- http://www.php.net/manual/en/function.ftp-put.php Edit Note --... -
note 33575 added to function.register-shutdown-function
If your script exceeds the maximum execution time, and terminates thusly: Fatal error: Maximum execution time of 20 seconds exceeded in - on line...



Reply With Quote

