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

怪我咯
Release: 2023-03-11 20:36:02
Original
1463 people have browsed it

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;
$人->吃饭();
……
Copy after login

. 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!