note 16814 modified in language.functions by levim
| From: | levim@php.net | Date: | Sun, 07 Jul 2013 18:43:26 +0000 |
| Subject: | note 16814 modified in language.functions by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195487@lists.php.net to get a copy of this message | ||
It is possible to define a function from inside another function.
The result is that the inner function does not exist until the outer function gets executed.
For example, the following code:
<?php
function a () {
function b() {
echo "I am b.\n";
}
echo "I am a.\n";
}
if (function_exists("b")) echo "b is defined.\n"; else echo "b is not
defined.\n";
a();
if (function_exists("b")) echo "b is defined.\n"; else echo "b is not
defined.\n";
?>
echoes:
b is not defined.
I am a.
b is defined.
Classes too can be defined inside functions, and will not exist until the outer function gets
executed.
--was--
It is possible to define a function from inside another function.
The result is that the inner function does not exist until the outer function gets executed.
For example, the following code:
function a () {
function b() {
echo "I am b.\n";
}
echo "I am a.\n";
}
if (function_exists("b")) echo "b is defined.\n"; else echo "b is not
defined.\n";
a();
if (function_exists("b")) echo "b is defined.\n"; else echo "b is not
defined.\n";
echoes:
b is not defined.
I am a.
b is defined.
Classes too can be defined inside functions, and will not exist until the outer function gets
executed.
http://php.net/manual/en/language.functions.php