How does scope work for functions in PHP? Can I use function A (defined outside function B) from within function B?
2
-
You could have made a simple test and find out by yourself...Catalin– Catalin2011-03-25 12:36:43 +00:00Commented Mar 25, 2011 at 12:36
-
2You are right, but I had a problem with this in a website but the culprit was a different problem. Anyway even if its is an "easy"question, I am sure it will be useful for somebody googling it, so no need to be so whiny.agente_secreto– agente_secreto2011-03-25 12:40:26 +00:00Commented Mar 25, 2011 at 12:40
Add a comment
|
3 Answers
From php manual:
All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.
So yes, you can.
Comments
Variable scope if for variables.
There is no "scope" for functions... except when using namespaces.
Quoting the User-defined functions section of the manual :
All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.