Defining a Class

When you declare a class, you are really making a template for the creation of objects. You list all the variables the object should have and all the functions it will need. Sometimes these are called properties and methods, respectively. Figure 6-1 displays the form of a class declaration. Note that inside the curly braces you can only declare variables with the var statement or declare functions. Listing 6.1 shows the definition of a class with three properties and two methods.

Figure 6-1. Defining a class.

When you declare a property, you don't specify a data type. It is a variable like any other, and it may contain an ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.