Creating an Object

Using OOP is a two-step process. The first—defining a class—you just did when you wrote the HtmlTemplate class. The second step is to make use of that class by creating an object (or a class instance).

Going back to my Human class analogy, an instance of this class may be called Jude. Jude's attributes are a gender of male, a height of about 40 inches, a weight of 35 pounds, and a birth date of November 15, 1998. Jude is one instance of the Human class and, as you may have noticed, is also a child. A second instance, Kelsey, has a female gender, a height of nearly 5 feet, a weight of 75 pounds, and a birth date of April 11, 1992. Both Jude and Kelsey are separate objects derived from the same class.

Creating an object is remarkably ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with O’Reilly online learning.

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