0
0
PHPprogramming~5 mins

Importing with use keyword in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADeclares a new class
BImports classes or namespaces for easier use
CStarts a PHP script
DDefines a function
How do you import multiple classes from the same namespace?
Ause Namespace\{Class1, Class2};
Bimport Namespace\Class1, Class2;
Cuse Namespace\Class1, Namespace\Class2;
Dinclude Namespace\Class1, Class2;
What is aliasing in PHP use statements?
ADeleting an imported class
BCreating a new namespace
CRenaming an imported class or namespace
DCalling a function
Which of these is a correct aliasing example?
Ause Vehicles\Car alias Auto;
Buse Vehicles\Car to Auto;
Cimport Vehicles\Car as Auto;
Duse Vehicles\Car as Auto;
Why should you use the use keyword?
ATo make code cleaner and avoid long names
BTo run PHP scripts faster
CTo declare variables
DTo comment code
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.