PHP类(初学)
程序员文章站
2022-06-01 17:35:42
...
类示例:Cat.php
name=func_get_arg(0); $this->age=func_get_arg(1); $this->color=func_get_arg(2); } }/* 不支持 * function __construct($name,$age,$color) { $this->name=$name; $this->age=$age; $this->color=$color; } */ public function getName() { return $this->name; } public function setName($name) { return $this->name=$name; } public function getAge() { return $this->age; } public function setAge($age) { $this->age=$age; } public function getColor() { return $this->color; } public function setColor($color) { $this->color=$color; } }?>
对象:
setName('蔡倩倩');$cat1->setAge(24);$cat1->setColor('白的'); */echo 'Cat1的姓名为:'.$cat1->getName().'
年龄为:'.$cat1->getAge();?>