Class is a blueprint or skeleton for an object.
Class members
Variables and methods declared within a class is called a member of the class.
Variable is called member variable, and method is called member method.
Member variable.
Declare member variable
public $name, $age;
Member methods
public function msg(){
}
Object
It is a real entity that has properties and methods.
Create object
$object = new ClassName();
Example
$person = new Person();
Example
class Person{
public $name, $age;
public function setDetails($name, $age){
$this->name = $name;
$this->age = $age;
}
public function display(){
echo "
Name: $this->name <br/>
Age: $this->age <br/>
";
}
}
$user = new Person();
$user->setDetails("Rama", 20);
$user->display();