Defining Classes
In this lesson, we will be learning about classes and how to define them.
We'll cover the following...
Syntax for Defining Classes #
We define our own class by starting with the keyword class
followed by the name you want to give to your new class.
Here’s the general syntax:
Press + to interact
class className{//properties and methods defined}
Example Snippet #
Here’s an example snippet of a class named Shape
.
Press + to interact
<?phpclass Shape{public $sides = 0; // first propertypublic $name= " "; // second propertypublic function description(){ //first methodecho "A $this->name with $this->sides sides.";}}?>