Defining a class
A
class is defined by using the class keyword, followed by the name of the
class and a pair of curly braces.
Let's return to our illustration:
<?php
class Dwarfs {
/* the class code... */
}
?>
Properties
Based on our Dwarfs class, each element of this class has the following possible Properties:
name, behavior, friend, age, etc.
<?php
class Dwarfs {
/* Properties */
public $nane;
public $behavior;
private $friend;
protected $age;
}
?>
Methods
Still based on our Dwarfs class, every function associated with each one of the Properties is called Method:
<?php
class Dwarfs {
/* Properties */
public $nane;
public $behavior;
private $friend;
protected $age;
/* Methods */
public function set_name($name)
{
$this->name = $name;
}
public function get_name()
{
return $this->name;
}
}
?>
<?php
class Dwarfs {
/* Properties */
public $nane;
public $behavior;
private $friend;
protected $age;
/* Methods */
function set_name($name)
{
$this->name = $name;
}
function get_name()
{
return $this->name;
}
}
?>