O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing Properties and Methods

The properties of an instance are variables, just like any other PHP variable. To refer to them, however, you must use the -> operator. You do not use a dollar sign in front of the property name. For an example, refer to the line in Listing 6.1 that prints the name property of the currentUser object.

Use of -> can be chained. If an object's property contains an object itself, you can use two -> operators to get to a property on the inner object. The parser in PHP 3 was unable to deal with complex expressions like this. In PHP 4 you are not limited this way. You may even place these expressions within double-quoted strings. See Listing 6.2 for an example of an object that contains an array of objects.

Unlike object-oriented ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required