Home  >  Article  >  Backend Development  >  What is the relationship between classes and objects in php? what is the difference

What is the relationship between classes and objects in php? what is the difference

怪我咯
怪我咯Original
2017-06-28 13:42:021509browse

For example, a class is like a human being. A class has various attributes and various methods. Just like a human being has attributes such as name, age, height, weight, etc., it also has attributes such as eating, sleeping, walking, etc.Behavior (method). The object is a specific person, an object instantiated from the human class. This person has various attributes and methods of humans. If you write the above conversation into code, it would be

class 人类{
public $姓名, $年龄, $身高, $体重……
public function 吃饭(){
……
}
public function 睡觉(){
……
}
public function 走路(){
……
}
……
}
$人=new 人类;
$人->姓名='李雷';
$人->年龄=30;
$人->身高=175;
$人->姓名=75;
$人->吃饭();
……

. This is the difference and relationship between classes and objects.

The above is the detailed content of What is the relationship between classes and objects in php? what is the difference. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn