[ Team LiB ] Previous Section Next Section

Q&A

Q1:

This hour introduced some unfamiliar concepts. Do I really need to understand object-oriented programming to become a good PHP programmer?

A1:

The short answer is no. Most PHP scripts use little or no object-oriented code at all. The object-oriented approach won't help you do things that you couldn't otherwise achieve. The benefits of object-oriented programming lie in the organization of your scripts, their reusability, and their extensibility. The benefits of object-oriented design can be enormous, however, which is one reason why PHP 5 provides extended support for objects.

Even if you decide not to produce object-oriented code, you might need to decipher third-party programs that contain classes. This hour should help you understand such code.

Q2:

I'm confused by the special variable $this.

A2:

Within a class, you sometimes need to call the class's methods or access its properties. By combining the $this variable and the -> operator, you can do both. The $this variable is the handle a class is automatically given to refer to itself and to its components.


    [ Team LiB ] Previous Section Next Section