Home >Backend Development >PHP Tutorial >Classes and object-oriented in PHP

Classes and object-oriented in PHP

巴扎黑
巴扎黑Original
2016-11-12 14:29:181320browse

The difference between classes and objects in PHP programming:
A class is abstract and represents a type of thing.
Object is concrete, a specific instance of a class.
A class is a template for an object, and an object is an individual instance of a class.
Concrete object-oriented examples

<?php  
//这就是一个类(狗类)  
class dog{  
   //属性  
   public $name;  
   public $age;  
   public $color;  
}  
//创建一只狗  
$dog1=new dog();  
//给这只猫赋值.(具体各个)  
$dog1->name="小白";  
$ dog1 ->age=3;  
$ dog 1->color="白色";  
$dog2=new Cat();  
$dog2->name="小花";  
$dog2->age=100;  
$dog2->color="颜色";  
//如果我们找到一只狗,只要找到 $dog1, 那么该变量所有相关的属性都通通的找到  
$findDogName="旺财";  
if($dog2->name==$findDogName){  
       echo $dog2->name."||".$dog2->age."||".$dog2->color;  
}  
?>


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