O'Reilly logo

Core PHP Programming, Third Edition 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

6.6. 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 line in Listing 6.1 that prints the name property of the user 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. You may even place these expressions within double-quoted strings. See Listing 6.5 for an example of an object that contains an array of objects.

Accessing methods is similar to accessing properties. The -> operator is used to point to the instance's method. This is shown in ...

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