0
0
PHPprogramming~10 mins

Namespace declaration syntax 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 namespace named MyApp.

PHP
<?php

namespace [1];

class User {}
Drag options to blanks, or click blank then click option'
Amyapp
BMyApp
CApp\My
DMy_App
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or underscores instead of the exact namespace name.
Adding extra backslashes or characters.
2fill in blank
medium

Complete the code to declare a nested namespace named App\Controllers.

PHP
<?php

namespace [1];

class HomeController {}
Drag options to blanks, or click blank then click option'
AApp\Controllers
BApp_Controllers
CApp.Controllers
DApp/Controllers
Attempts:
3 left
💡 Hint
Common Mistakes
Using forward slashes or dots instead of backslashes.
Using underscores instead of backslashes.
3fill in blank
hard

Fix the error in the namespace declaration syntax.

PHP
<?php

[1] MyApp;

class Product {}
Drag options to blanks, or click blank then click option'
Anamespace
Bnamespace;
Cnamespaces
DNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing the keyword.
Adding a semicolon after the keyword.
4fill in blank
hard

Fill both blanks to declare a namespace and define a class inside it.

PHP
<?php

[1] [2];

class Order {}
Drag options to blanks, or click blank then click option'
Anamespace
BOrderApp
COrders
Dnamespace;
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a semicolon after the keyword in the first blank.
Using an incorrect namespace name.
5fill in blank
hard

Fill all three blanks to declare a nested namespace and define a class inside it.

PHP
<?php

[1] [2]\[3];

class Customer {}
Drag options to blanks, or click blank then click option'
Anamespace
BApp
CModels
DNamespace
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing the keyword.
Using forward slashes or dots instead of backslashes.
Adding extra characters or spaces.