Recall & Review
beginner
What does the
use keyword do in PHP?The
use keyword imports classes, functions, or namespaces so you can use them without writing the full path every time.Click to reveal answer
beginner
How do you import a class named <code>Car</code> from the namespace <code>Vehicles</code>?You write: <br>
use Vehicles\Car;<br>This lets you use Car directly in your code.Click to reveal answer
intermediate
Can you import multiple classes from the same namespace using <code>use</code>?Yes. You can import multiple classes by listing them separated by commas:<br><code>use Vehicles\{Car, Bike, Truck};</code>Click to reveal answer
intermediate
What is aliasing in PHP
use statements?Aliasing lets you rename an imported class or namespace to a shorter or different name using <code>as</code>.<br>Example:<br><code>use Vehicles\Car as Auto;</code>Click to reveal answer
beginner
Why is importing with
use helpful in PHP?It makes code cleaner and easier to read by avoiding long full paths. It also helps avoid name conflicts by using aliases.
Click to reveal answer
What does the PHP
use keyword do?✗ Incorrect
The
use keyword imports classes or namespaces so you can use them without full paths.How do you import multiple classes from the same namespace?
✗ Incorrect
You use curly braces to import multiple classes from the same namespace:
use Namespace\{Class1, Class2};What is aliasing in PHP
use statements?✗ Incorrect
Aliasing lets you rename an imported class or namespace using
as.Which of these is a correct aliasing example?
✗ Incorrect
The correct syntax for aliasing is
use Namespace\Class as Alias;Why should you use the
use keyword?✗ Incorrect
Using
use makes code cleaner and easier to read by avoiding long full paths.Explain how the
use keyword helps when working with namespaces in PHP.Think about how you avoid writing long names repeatedly.
You got /4 concepts.
Describe how to import multiple classes from the same namespace and how to rename one using aliasing.
Remember the special syntax with braces and the keyword 'as'.
You got /4 concepts.