Recall & Review
beginner
What is the global namespace in PHP?
The global namespace is the default space where PHP code runs if no namespace is declared. It contains all global functions, classes, and constants.
Click to reveal answer
beginner
How do you access a global function from inside a namespace in PHP?
Use a backslash (\) before the function name to access it from the global namespace, for example: \strlen('text').
Click to reveal answer
beginner
What does the leading backslash (\) mean in PHP code?
It tells PHP to look for the function, class, or constant in the global namespace, ignoring the current namespace.
Click to reveal answer
intermediate
Example: How to call the global PHP function array_merge inside a namespace?
Inside a namespace, call it as \array_merge($arr1, $arr2) to ensure you use the global function, not a namespaced one.
Click to reveal answer
intermediate
Why is global namespace access important in PHP namespaces?
It prevents naming conflicts by explicitly calling global functions or classes when inside a namespace, ensuring correct code behavior.
Click to reveal answer
In PHP, how do you call the global function strlen inside a namespace?
✗ Incorrect
Using \strlen('text') calls the global function ignoring the current namespace.
What does the leading backslash (\) do in PHP namespaces?
✗ Incorrect
The leading backslash tells PHP to use the global namespace.
If you omit the leading backslash when calling a function inside a namespace, what happens?
✗ Incorrect
Without the backslash, PHP looks for the function inside the current namespace.
Which of these is a correct way to access a global constant inside a namespace?
✗ Incorrect
Using \PHP_VERSION accesses the global constant explicitly.
Why might you want to use global namespace access in PHP?
✗ Incorrect
Global namespace access helps avoid conflicts by explicitly calling global code.
Explain how to call a global function from inside a PHP namespace and why it is necessary.
Think about how PHP searches for functions inside namespaces.
You got /3 concepts.
Describe the role of the global namespace in PHP and how it interacts with user-defined namespaces.
Consider what happens when you don't use namespaces.
You got /4 concepts.