0
0
PHPprogramming~10 mins

Composer autoload mechanism 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 include Composer's autoload file.

PHP
<?php
require_once '[1]';
Drag options to blanks, or click blank then click option'
Avendor/composer.json
Bcomposer.json
Cvendor/autoload.php
Dautoload.php
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'composer.json' instead of the autoload file.
Forgetting to include the 'vendor/' directory in the path.
2fill in blank
medium

Complete the code to instantiate a class loaded by Composer's autoloader.

PHP
<?php
require_once 'vendor/autoload.php';
$object = new [1]();
Drag options to blanks, or click blank then click option'
Amyclass
BMyClass
Cmy_class
DClassMy
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or snake_case instead of PascalCase.
Misspelling the class name.
3fill in blank
hard

Fix the error in the autoloading by completing the namespace prefix in Composer's PSR-4 autoload config.

PHP
"autoload": {
    "psr-4": {
        "[1]": "src/"
    }
}
Drag options to blanks, or click blank then click option'
AApp\
Bapp
Capp\
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the trailing backslash.
Using lowercase instead of capitalized namespace.
4fill in blank
hard

Fill both blanks to create a classmap autoload configuration for the 'lib' directory.

PHP
"autoload": {
    "[1]": ["[2]"]
}
Drag options to blanks, or click blank then click option'
Aclassmap
Blib
Cpsr-4
Dsrc
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'psr-4' instead of 'classmap' for directories without namespaces.
Incorrect directory name.
5fill in blank
hard

Fill all three blanks to define a PSR-4 autoload for namespace 'Vendor\Package' pointing to 'src/' directory.

PHP
"autoload": {
    "[1]": {
        "[2]": "[3]"
    }
}
Drag options to blanks, or click blank then click option'
Apsr-4
BVendor\Package\
Csrc/
Dclassmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'classmap' instead of 'psr-4' for PSR-4 autoload.
Omitting the trailing backslash in the namespace.
Wrong directory path.