If I use function_exists
as following:
if ( ! function_exists( 'get_value' ) ) :
function get_value( $field ) {
..
return $value;
}
endif;
Now, when I call the function in the same file before the above function, it will give fatal error:
Fatal error: Call to undefined function get_value() ...
But, if i call it after the above function, it will return the value without any error.
Now, if I remove the function_exists condition, ie:
function get_value( $field ) {
..
return $value;
}
Then it will work if i call this function before or after in the same document. Why is this so?
If you define the function directly without the if statement, it will be created while parsing / compiling the code and as a result it is available in the entire document.
If you put it inside the if, it will be created when executing the if statement and so it is not possible to use it before your definition. At this point, everything written above the if statement is executed already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With