function declare_dada($sayhello) {
if ($sayhello) {
function dada() {
return("Hello! I am dada");
}
} else {
function dada() {
return("I am dada");
}
}
}
declare_dada(false);
echo dada();
Depending on the value that you give declare_dada(), the function dada will be declared with different code...
I never knew that you could declare function in PHP (5) within conditional and other function blocks.
Note that declaring a function twice (for example by calling declare_dada() twice) will result in a
Fatal Error, a type of error which cannot be caught (not without using ugly tricks such as parsing buffered output). Therefore overuse of conditional declaration can cause your code to ungracefully die halfway through execution.