O'Reilly logo

PHP Advanced for the World Wide Web: Visual QuickPro Guide by Larry Ullman

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

Defining a Class

To use OOP, you must begin by defining a class. Classes consist of variables and functions, which are also referred to as attributes (or properties) and methods, respectively.

A philosophical example of a class would be Human. A Human class would have characteristics (or attributes) of gender, height, weight, birth date, and so forth. The actions (or methods) of a Human could be eating, sleeping, and more. A class, in short, is a generalized description of a thing.

The syntax of a class, in the simplest form, is:

class ClassName { 
   var $variable_name;
   function FunctionName () {
        // Function code.
   }
}

Notice that within the class you must use the var statement to identify your variables. You may, at this time, give the variables ...

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