Specifications
FIGURE 6.1
PHP does not support multiple inheritance.
The left combination shows class C inheriting from class B, which in turn inherits from class
A. Each class has at most one parent, so this is a perfectly valid single inheritance in PHP.
The center combination shows class B and C inheriting from class A. Each class has at most
one parent, so again this is a valid single inheritance.
The right combination shows class C inheriting from both class A and class B. In this case,
class C has two parents, so this is multiple inheritance and is invalid in PHP.
Designing Classes
Now that you know some of the concepts behind objects and classes and the syntax to imple-
ment them in PHP, it is time to look at how to design useful classes.
Many classes in your code will represent classes or categories of real-world objects. Classes
you might use in Web development might include pages, user interface components, shopping
carts, error handling, product categories, or customers.
Objects in your code can also represent specific instances of the previously mentioned classes,
for example, the home page, a particular button, or the shopping cart in use by Fred Smith at a
particular time. Fred Smith himself can be represented by an object of type customer. Each
item that Fred purchases can be represented as an object, belonging to a category or class.
In the previous chapter, we used simple include files to give our fictional company, TLA
Consulting, a consistent look and feel across the different pages of their Web site. Using
classes and the timesaving power of inheritance, we can create a more advanced version of the
same site.
We want to be able to quickly create pages for TLA that look and behave in the same way.
Those pages should be able to be modified to suit the different parts of the site.
Using PHP
P
ART I
158
A
B
C
Single Inheritance
A
B C
Single Inheritance
A B
C
Multiple Inheritance
08 7842 CH06 3/6/01 3:34 PM Page 158