Bird
0
0

Why does heavy use of global state in PHP often lead to bugs that are hard to reproduce?

hard📝 Conceptual Q10 of 15
PHP - Request Lifecycle
Why does heavy use of global state in PHP often lead to bugs that are hard to reproduce?
ABecause global variables are reset after each function call
BBecause global state creates hidden dependencies and unpredictable interactions
CBecause PHP automatically locks global variables during execution
DBecause global variables cannot be accessed inside classes
Step-by-Step Solution
Solution:
  1. Step 1: Understand global state behavior

    Global variables can be changed anywhere, creating hidden dependencies.
  2. Step 2: Explain why bugs are hard to reproduce

    Unpredictable interactions from shared state cause bugs that depend on execution order and timing.
  3. Final Answer:

    Because global state creates hidden dependencies and unpredictable interactions -> Option B
  4. Quick Check:

    Global state causes hidden dependencies = true [OK]
Quick Trick: Hidden dependencies cause unpredictable bugs [OK]
Common Mistakes:
  • Thinking globals reset after each function
  • Believing PHP locks globals automatically
  • Assuming globals are inaccessible in classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes