I'm not in OOP and I would like understand why in the procedural mode I can declare a function nestled in a function without errors, but I can call the nestled function from the "main" and cannot call from the primary function?
Example 1: calling b() in a() gives Fatal error / Why a() doesn't views b() ?
<?php
function a(){
// do something
b(); //Fatal error: Call to undefined function b()
function b(){
// do something
}
}
a();
Example 2: calling b() from the main gives Fatal error (this is logic)
<?php
function a(){
// do something
function b(){
// do something
}
}
b(); // Fatal error: Call to undefined function b()
Example 3: calling a() and then calling b() from the main doesn't give error
<?php
function a(){
// do something
function b(){
// do something
}
}
a();
b();
a()once during the whole execution of your script.b()is only declared once you first calla(), and will raise an error about redeclaring an existing function if you ever calla()again. Both functions will be declared in global scope, which isn't necessarily obvious.