Recall & Review
beginner
What is a namespace in PHP?
A namespace in PHP is a way to group related code like classes, functions, and constants under a unique name to avoid name conflicts.
Click to reveal answer
beginner
Why do we need namespaces in PHP?
Namespaces help avoid conflicts when different parts of a program use the same names for classes or functions by keeping them separate.
Click to reveal answer
intermediate
How do namespaces prevent name collisions?
Namespaces add a unique prefix to names, so two classes with the same name can exist in different namespaces without clashing.
Click to reveal answer
intermediate
What happens if you don't use namespaces in large PHP projects?
Without namespaces, you risk errors because classes or functions with the same name can overwrite each other, causing bugs.
Click to reveal answer
beginner
Give a real-life example of why namespaces are useful.
Imagine two friends both named 'Alex' in a room. Without last names, you get confused. Namespaces act like last names to tell them apart.
Click to reveal answer
What problem do namespaces solve in PHP?
✗ Incorrect
Namespaces prevent name conflicts by grouping code under unique names.
How do namespaces help in large projects?
✗ Incorrect
Namespaces organize code and prevent conflicts in big projects.
Which of these is a correct way to declare a namespace in PHP?
✗ Incorrect
The 'namespace' keyword declares a namespace in PHP.
What happens if two classes have the same name but are in different namespaces?
✗ Incorrect
Namespaces allow classes with the same name to coexist without conflict.
Which of these is NOT a benefit of namespaces?
✗ Incorrect
Namespaces do not fix bugs automatically; they help organize code and avoid name conflicts.
Explain in your own words why namespaces are important in PHP programming.
Think about what happens when two parts of code use the same name.
You got /4 concepts.
Describe a simple real-life example that helps you understand the purpose of namespaces.
Imagine two friends named Alex in the same room.
You got /4 concepts.