From the course: PHP: Exporting Data to Files

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Autoloading classes

Autoloading classes - PHP Tutorial

From the course: PHP: Exporting Data to Files

Start my 1-month free trial

Autoloading classes

In this course, we'll be using a lot of custom PHP classes, some of them written by me, others from open source libraries. Before you can use a class, the class definition needs to be included in your script. This gets cumbersome with a large number of classes. It's a lot simpler to use an autoloader to find and load class definitions automatically when they're needed. We'll be using a PSR-4 autoloader, which is designed to work with namespaced classes. PSR stands for PHP specification request. And it's part of a series of recommendations adopted by the PHP Framework Interop Group. The group represents about 30 PHP frameworks including Drupal, Laravel, and Symfony. So although its standards don't have any official standing they're widely implemented. To use the autoloader, each class definition must be in a file with the same name as the class. And the folder structure must match the name space. Most of the classes we'll be using follow that convention. So the autoloader will work for…

Contents