Chapter 8. Objects

This chapter introduces not just objects, but the whole concept of object-oriented programming (OOP). This style of programming is a great way to build modular, reusable code, letting you create large applications that are relatively easy to maintain. The OOP approach has become very popular with the PHP community in recent years.

You may already be familiar with OOP from working with other languages such as Java, C#, or Perl, but if you're not, a general introduction follows shortly.

The rest of the chapter teaches the main concepts of OOP, and shows how to write object-oriented code in PHP. You learn:

  • How to define classes, which are the blueprints from which objects are made. You then learn how to create objects from classes

  • Two important components of objects — properties and methods — and how to use them to add rich functionality to your objects. Along the way you learn how to make your objects as self-contained as possible, which allows them to be readily reused for different purposes

  • How to use inheritance — a process where one object inherits behavior from another. This is one of the most powerful aspects of objects. You learn how to achieve this in PHP, and how to fine-tune the inheritance process to create robust classes that you can use again and again

  • Other OOP concepts such as abstract classes, interfaces, constructors, and destructors

  • Some of PHP's handy object-related functions for automatically loading classes, converting objects to strings, and identifying ...

Get Beginning PHP 5.3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.