O'Reilly logo

Learning PHP and MySQL by Jon A. Phillips, Michele E. Davis

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

Object-Oriented Programming

Object-Oriented programming follows the same goals that we discussed when introducing functions, principally to make reusing code easier. It uses classes to group functions and variables together as an object. It may help to think of objects as little black boxes that can do work without you knowing exactly how it's done.

They still use functions, but they get a new name when defined in classes. They're called methods. The class works as a blue print for creating objects of that type. Variables can still be defined in methods, but they gain the new ability to be defined as part of the class itself.

When a new object is created from a class, it is called an instance of that class. Any variables that are defined in the class get separate storage space in each instance. The separate storage for variables provides the instance of an object with the ability to remember information between method executions. Figure 5-3 demonstrates the relationship between a class and its components.

A class can contain methods and attributes (variables)

Figure 5-3. A class can contain methods and attributes (variables)

If you're new to the concepts of OO programming, don't worry about understanding everything right away. We'll work with a class in Chapter 7, so it's good enough just to know how to call the methods. In fact, anything that can be done with objects can be done with plain functions. It's just a matter of style and ...

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