Creating an Object

Once you have defined a class, you use the new statement to create an instance of the class, an object. If the definition of the class is the blueprint, the instance is the widget rolling off the assembly line. The new statement expects the name of a class and returns a new instance of that class. If a constructor with parameters has been declared, you may also follow the class name with parameters inside parentheses. Look for the line in Listing 6.1 that uses the new statement.

When you create an instance, memory is set aside for all the properties. Each instance has its own set of properties. However, the methods are shared by all instances of that class.

As you recall, PHP allows you to create variables without explicitly ...

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.