From the course: PHP: Object-Oriented Programming
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Autoload undefined classes - PHP Tutorial
From the course: PHP: Object-Oriented Programming
Autoload undefined classes
- [Instructor] In this movie we'll learn how to get PHP to automatically load classes which are undefined. The way we're going to do that with another magic method called autoload, __autoload. Now, this is a little different from our other magic methods, because we define those inside our classes. Autoload is going to go outside of the class. This is a function that's going to be called automatically, whenever PHP encounters the name of a class that it doesn't know about. Before it gives up and throws an error, it's going to call autoload, that will provide us an opportunity to locate the class definition for it. In PHP 4 and 5, we simply defined this magic method, function __autoload, and then one argument, The argument is the class name that PHP is currently looking for. So here I'm just echoing back something saying the definition for the class is missing. So if we have PHP code like this and it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.