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 ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.