Recall & Review
beginner
What is global state in PHP?
Global state refers to variables or data that are accessible from anywhere in the program, not limited to a specific function or class.
Click to reveal answer
beginner
Why can global state make debugging harder in PHP?
Because any part of the code can change global variables, it becomes difficult to track where and why a value changed, leading to confusing bugs.
Click to reveal answer
intermediate
How does global state affect code testing in PHP?
Global state makes testing harder because tests can interfere with each other by changing shared data, causing unpredictable results.
Click to reveal answer
beginner
What is a safer alternative to using global state in PHP?
Using local variables, passing data through function parameters, or using objects to encapsulate state helps keep data controlled and predictable.
Click to reveal answer
intermediate
Give an example of a problem caused by global state in PHP.
If two functions change the same global variable, one function might overwrite the other's data unexpectedly, causing errors or wrong results.
Click to reveal answer
What does global state mean in PHP?
✗ Incorrect
Global state means variables that can be accessed and changed from any part of the program.
Why is global state dangerous for debugging?
✗ Incorrect
Global state hides where variables are changed, making bugs hard to find.
How does global state affect testing?
✗ Incorrect
Global state causes tests to share data, which can make test results unpredictable.
What is a better way than using global state?
✗ Incorrect
Using local variables and passing data clearly keeps code easier to understand and safer.
What problem can happen if two functions change the same global variable?
✗ Incorrect
Shared global variables can be overwritten unexpectedly, causing errors.
Explain why global state can cause bugs in PHP programs.
Think about how many places can change the same data.
You got /4 concepts.
Describe how using local variables and passing data can improve PHP code compared to using global state.
Consider how data moves clearly between parts of the program.
You got /4 concepts.