PHP supports nested function based on certain criteria.
Please look over the code.
function Media(){ }
function Audio()
{
echo "Plugged Audo 5.1:<br/>";
function Volume()
{
echo "Volume controls:<br/>";
function Equalizer()
{
echo "Equalize Bands:<br/>";
}
}
}
//Call to nested functions
Audio();
Volume();
Equalizer();
if(function_exists('Volume')):
echo "TRUE";
else:
echo "FALSE";
endif;
Case 1: //Result :Works Well
--------
Audio();
Volume();
Equalizer();
Case 2: //Results Notice Error. Root function Audio must be called first.
--------
Volume();
Case 3: //Results Error. Root function Volume must be called.
--------
Audio();
Equalizer();
Note :
The nested function should be called based on their order used.
In our example when Audio is not called and instantly when we try to call Volume puts under error.
Even though there is an possibility to use nested functions in PHP. It looks overhead to do so. Better to avoid in logical ground of script.
Tested on PHP 5.5.32