Page 203 - Beginning PHP 5.3
P. 203
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 an object ’ s class
OOP is a big topic, and this chapter introduces quite a lot of concepts. Don ’ t worry if it all seems
overwhelming at first. Plenty of code examples make things clearer, and you ’ ll find that, once you
start writing your own object - oriented code, the concepts will fit into place.
9/21/09 9:03:30 AM
c08.indd 165 9/21/09 9:03:30 AM
c08.indd 165