To eliminate this
additional task, the concept of autoloading objects was introduced in PHP 5. Autoloading
allows you to define a special __autoload function that is automatically called whenever
a class is referenced that hasn??™t yet been defined in the script. You can eliminate
the need to manually include each class file by defining the following function:
function __autoload($class) {
require_once("classes/$class.class.php");
}
Defining this function eliminates the need for the require_once() statements because
when a class is invoked for the first time, __autoload() will be called, loading the class
according to the commands defined in __autoload(). This function can be placed in
a global application configuration file, meaning only that function will need to be
made available to the script.
?– Note The require_once() function and its siblings were introduced in Chapter 3.
Summary
This chapter introduced object-oriented programming fundamentals, followed by an
overview of PHP??™s basic object-oriented features, devoting special attention to those
enhancements and additions that were made available with the PHP 5 release.
The next chapter expands upon this introductory information, covering topics such as
inheritance, interfaces, abstract classes, and more.
193
?– ?– ?–
C H A P T E R 7
Advanced OOP Features
Chapter 6 introduced the fundamentals of object-oriented programming (OOP).
Pages:
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271