Quantcast
Channel: Defining a function inside a conditional - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by Mark Baker for Defining a function inside a conditional

You're trying to execute foo() before testing to see whether it's defined or not (and subsequently defining it)if(!function_exists("foo")) { function foo() { // do soemething } } foo();

View Article



Answer by NikiC for Defining a function inside a conditional

See http://www.php.net/manual/en/functions.user-defined.php:Functions need not be defined before they are referenced, except when a function is conditionally defined [...] Its definition must be...

View Article

Defining a function inside a conditional

Snippet 1 works. Snippet 2 doesn't. Why?1.foo();function foo(){ // do soemething}2.foo();if(!function_exists("foo")){ function foo() { // do soemething }}

View Article
Browsing all 3 articles
Browse latest View live




Latest Images