Home >Backend Development >PHP Tutorial >What is the relationship between classes and objects in php? what is the difference
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!