Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to alias the class OriginalClass as AliasClass.
PHP
<?php
use Some\Namespace\OriginalClass [1] AliasClass;
$obj = new AliasClass();
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alias' instead of 'as' keyword.
Trying to rename the class without 'as'.
✗ Incorrect
In PHP, the
as keyword is used to create an alias for a class when importing it with use.2fill in blank
mediumComplete the code to alias the function originalFunction as aliasFunction.
PHP
<?php
use function Some\Namespace\originalFunction [1] aliasFunction;
aliasFunction();
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rename' or 'alias' instead of 'as'.
Omitting the 'as' keyword.
✗ Incorrect
The
as keyword is used to alias functions when importing them with use function.3fill in blank
hardFix the error in aliasing the constant ORIGINAL_CONST as ALIAS_CONST.
PHP
<?php
use const Some\Namespace\ORIGINAL_CONST [1] ALIAS_CONST;
echo ALIAS_CONST;
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alias' or 'rename' instead of 'as'.
Trying to use 'const' keyword again.
✗ Incorrect
The
as keyword is used to alias constants when importing them with use const.4fill in blank
hardFill both blanks to alias a class and a function from the same namespace.
PHP
<?php use Some\Namespace\OriginalClass [1] AliasClass; use function Some\Namespace\originalFunction [2] aliasFunction; $obj = new AliasClass(); aliasFunction(); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keywords for class and function aliasing.
Omitting the alias keyword.
✗ Incorrect
The
as keyword is used to alias both classes and functions when importing.5fill in blank
hardFill all three blanks to alias a class, a function, and a constant from the same namespace.
PHP
<?php use Some\Namespace\OriginalClass [1] AliasClass; use function Some\Namespace\originalFunction [2] aliasFunction; use const Some\Namespace\ORIGINAL_CONST [3] ALIAS_CONST; $obj = new AliasClass(); aliasFunction(); echo ALIAS_CONST; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keywords for different types of imports.
Forgetting to alias constants properly.
✗ Incorrect
The
as keyword is consistently used to alias classes, functions, and constants in PHP imports.