Recall & Review
beginner
What is the purpose of Composer's autoload mechanism?
Composer's autoload mechanism automatically loads PHP classes when they are needed, so you don't have to manually include or require class files.Click to reveal answer
beginner
Which file does Composer generate to handle autoloading?
Composer generates a file called
vendor/autoload.php that you include in your project to enable autoloading of classes.Click to reveal answer
beginner
How do you include Composer's autoload file in your PHP script?
Use
require 'vendor/autoload.php'; at the beginning of your PHP script to enable autoloading.Click to reveal answer
intermediate
What are PSR-4 and PSR-0 in the context of Composer autoloading?
PSR-4 and PSR-0 are standards for autoloading PHP classes based on namespaces and file paths. Composer supports these to map namespaces to directories automatically.
Click to reveal answer
intermediate
How do you define autoloading rules in Composer?
You define autoloading rules in the
composer.json file under the autoload section, specifying namespaces and their corresponding directories.Click to reveal answer
What file must you include to use Composer's autoloading?
✗ Incorrect
Composer generates the vendor/autoload.php file to handle autoloading of classes.
Which autoloading standard maps namespaces to directory paths?
✗ Incorrect
PSR-4 defines how namespaces correspond to directory structures for autoloading.
Where do you specify autoloading rules in a Composer project?
✗ Incorrect
The autoload section in composer.json defines how classes are autoloaded.
What command updates the autoload files after changing composer.json?
✗ Incorrect
The command 'composer dump-autoload' regenerates the autoload files.
What happens if you forget to include vendor/autoload.php?
✗ Incorrect
Without including vendor/autoload.php, PHP won't know how to load classes automatically.
Explain how Composer's autoload mechanism works and why it is useful.
Think about how PHP finds classes without you writing many include statements.
You got /4 concepts.
Describe how to set up PSR-4 autoloading in a Composer project.
Focus on the steps from defining rules to using autoload in your code.
You got /4 concepts.