0
0
PHPprogramming~10 mins

Importing with use keyword in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the class MyClass from the namespace App\Utils.

PHP
<?php
use App\Utils\[1];

$obj = new MyClass();
Drag options to blanks, or click blank then click option'
AUtils
BClass
CApp
DMyClass
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the namespace instead of the class
Forgetting to use the full namespace path
2fill in blank
medium

Complete the code to import the Helper class from the Library\Tools namespace.

PHP
<?php
use Library\Tools\[1];

$helper = new Helper();
Drag options to blanks, or click blank then click option'
AHelper
BLibrary
CTools
DTool
Attempts:
3 left
💡 Hint
Common Mistakes
Using the namespace name instead of the class
Misspelling the class name
3fill in blank
hard

Fix the error in the import statement to correctly import Database\Connection.

PHP
<?php
use Database\[1];

$conn = new Connection();
Drag options to blanks, or click blank then click option'
AConnector
BConnection
CConnections
DConnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name
Adding extra letters or missing letters
4fill in blank
hard

Fill both blanks to import Mailer from Services\Email and create an instance.

PHP
<?php
use Services\[1]\[2];

$mail = new Mailer();
Drag options to blanks, or click blank then click option'
AEmail
BMailer
CService
DMail
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping namespace and class names
Using incorrect namespace parts
5fill in blank
hard

Fill all three blanks to import Logger from Framework\Utils\Log and create an instance.

PHP
<?php
use Framework\[1]\[2]\[3];

$log = new Logger();
Drag options to blanks, or click blank then click option'
AUtils
BLog
CLogger
DLogs
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up namespaces and class names
Using plural forms incorrectly