The basics of a Class in PHP

Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class.

A class may contain its own constants, variables (called “properties”), and functions (called “methods”).


class SimpleClass
// property declaration
public $var = ‘hello’;

// method declaration
public function displayVar() {
echo $this->var;

$a = new SimpleClass();