Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

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 languages, such as C++, PHP does not allow properties of classes
to be private. Any code may reach into the instance and change or read the values of
properties.


Accessing methods is similar to accessing properties. The -> operator is used to point to
the instance's method. This is shown in Listing 6.1 in the call to getLastLogin. Methods
behave exactly as functions defined outside classes.


If a class extends another, the properties and methods of all ancestor classes are available
in the child class, despite not being declared explicitly. As mentioned previously,
inheritance is very powerful. If you wish to access an inherited property, simply refer to it
as you would any other local property.


Three functions allow you to get information about a class as your script runs:
get_class, get_parent_class, and method_exists. These functions are described in
Chapter 8.


Listing 6.2 Objects Containing Other Objects

Free download pdf