...

/

Defining Classes

Defining Classes

In this lesson, we will be learning about classes and how to define them.

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
<?php
class Shape{
public $sides = 0; // first property
public $name= " "; // second property
public function description(){ //first method
echo "A $this->name with $this->sides sides.";
}
}
?>

Explanation

...