4.1. Introducing Object-Oriented Programming

Object-oriented programming, sometimes shortened to just OOP, isn't just a matter of using different syntax. It's a different way of analyzing programming problems. The application is designed by modeling the programming problem. For example, a programmer designing an application to support a company's sales department might look at the programming project in terms of the relationships between customers and sales and credit lines — in other words, in terms of the design of the sales department itself.

In object-oriented programming, the elements of a script are objects. The objects represent the elements of the problem your script is meant to solve. For example, if the script is related to a used-car lot, the objects are probably cars and customers. Or if the script is related to outer space, the objects would probably be stars and planets.

Object-oriented programming developed new concepts and new terminology to represent those concepts. Understanding the terminology is the road to understanding object-oriented programming.

4.1.1. Objects and classes

The basic elements of object-oriented programs are objects. It's easiest to understand objects as physical objects. For example, a car is an object. A car has properties (also called attributes), such as color, model, engine, and tires. A car has things it can do, too, such as move forward, move backward, park, roll over, and play dead (well, ours does anyway).

In general, objects are ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.