Bird
0
0

What is the scope of a variable declared inside a PHP function without using global?

easy📝 Conceptual Q11 of 15
PHP - Functions
What is the scope of a variable declared inside a PHP function without using global?
AIt is accessible only outside the function.
BIt is global and accessible everywhere.
CIt is static and retains value between calls.
DIt is local to the function only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable declaration inside functions

    Variables declared inside a function are local by default, meaning they exist only within that function.
  2. Step 2: Recall the role of the global keyword

    Without using global, the variable does not refer to any global variable with the same name.
  3. Final Answer:

    It is local to the function only. -> Option D
  4. Quick Check:

    Local scope = inside function only [OK]
Quick Trick: Variables inside functions are local unless declared global [OK]
Common Mistakes:
  • Assuming variables inside functions are global by default
  • Confusing local variables with static variables
  • Thinking variables inside functions affect global variables automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes