Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 3
    I might be wrong, but your answer might be half correct. If the function was declared outside and after the if, it would work... The file is initially parsed and if the function is outside the if it would be available at anytime. Commented Jan 13, 2014 at 17:57
  • No you're correct Jose - This answer is misleading. It doesn't work because the function is conditionally defined. If the function was declared in the global scope, it could be invoked anywhere, even at a position in the file before it is defined. Commented Jan 13, 2014 at 17:58
  • In this case, accidentally, yes, because the outer scope is completely evaluated (including declarations) before the inner scope is executed. Elaborated a bit to clarify this PHP peculiarity. Commented Jan 13, 2014 at 17:58