<?php
class Fruit {
// Properties
public $name;
public $color;
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
?>
Note: In a class, variables are called properties and functions are called methods!
N.B. The above code is used for creating a class called "Fruit". It is a template so does not have any data to display. It may be put in a Class file called Fruit.php for deployment in any PHP web page and reused whenever needed.