PHP Basic Class
An object in PHP contains variables and functions. Objects typically belong to a class, which defines the variables and functions that all objects of this class will contain.
The syntax to define a class is:
Once a class is defined, you can create an instance using:
Variables and functions on the object are accessed like this:
"A shape with 6 sides"
Classes can define a special __construct() method, which is executed as part of object creation. This is often used to specify the initial values of an object:
A shape with 6 sides
Extending Another Class
Class definitions can extend existing class definitions, adding new variables and functions as well as modifying those defined in the parent class.
Here is a class that extends the previous example:
The Square class contains variables and behavior for both the Shape class and the Square class: