0
0
PHPprogramming~5 mins

Why global state is dangerous in PHP - Quick Recap

Choose your learning style9 modes available
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?
AVariables that never change
BVariables accessible everywhere in the program
CVariables only inside a function
DVariables stored in a database
Why is global state dangerous for debugging?
ABecause it prevents variable changes
BBecause it makes code run faster
CBecause it hides where variables change
DBecause it only works in PHP
How does global state affect testing?
ATests can interfere by sharing data
BTests do not need data
CTests become faster
DTests run independently without issues
What is a better way than using global state?
AUsing global constants only
BUsing more global variables
CAvoiding variables completely
DUsing local variables and passing data explicitly
What problem can happen if two functions change the same global variable?
AOne function might overwrite the other's data
BThey will never run
CThe variable becomes constant
DThe program crashes immediately
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.