0
0
PHPprogramming~10 mins

Sub-namespaces 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 declare a sub-namespace inside the main namespace.

PHP
<?php
namespace App\\[1];

class User {}
Drag options to blanks, or click blank then click option'
AControllers
BHelpers
CViews
DModels
Attempts:
3 left
💡 Hint
Common Mistakes
Using a sub-namespace name that does not match the folder structure.
Forgetting to use double backslashes in the namespace declaration.
2fill in blank
medium

Complete the code to use a class from a sub-namespace with the correct fully qualified name.

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

$user = new User();
Drag options to blanks, or click blank then click option'
AControllers
BHelpers
CModels
DServices
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong sub-namespace in the use statement.
Forgetting to import the class before using it.
3fill in blank
hard

Fix the error in the namespace declaration by completing the sub-namespace correctly.

PHP
<?php
namespace App\\[1]\\Services;

class Payment {}
Drag options to blanks, or click blank then click option'
ABilling
BControllers
CModels
DHelpers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a sub-namespace that does not match the service's purpose.
Omitting the sub-namespace and causing class conflicts.
4fill in blank
hard

Fill both blanks to create a nested sub-namespace and declare a class inside it.

PHP
<?php
namespace App\\[1]\\[2];

class Logger {}
Drag options to blanks, or click blank then click option'
AUtils
BHelpers
CCore
DServices
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of sub-namespaces.
Using invalid namespace names that don't follow naming conventions.
5fill in blank
hard

Fill all three blanks to import a class from a nested sub-namespace and create its instance.

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

$logger = new Logger();
Drag options to blanks, or click blank then click option'
AUtils
BHelpers
CLogger
DServices
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to include the class name in the use statement.
Using incorrect sub-namespace names or order.