如果用__set和__get 就没有办法了除非用get/set 方法 我最讨厌java 1000行代码的类 300行get/set
<?php
class Orange{
private $one; private $two;
public function setOne($one)
{
$this->one = $one;
} public function getOne()
{
return $this->one;
} public function setTwo($two)
{
$this->two = $two;
} public function getTwo()
{
return $this->two;
}
}
<?php
class Orange{
private $one; private $two;
public function setOne($one)
{
$this->one = $one;
} public function getOne()
{
return $this->one;
} public function setTwo($two)
{
$this->two = $two;
} public function getTwo()
{
return $this->two;
}
}
你 __get、__set 的属性是在程序运行时才会出现,自然是不能提示的
但是你在程序设计时应加入合法性检查,这样在程序联调时就容易发现问题了
为了编程时方便些,也可以做些容错设计。比如属性名可以有 英文全名、英文缩写、中文全名、汉语拼音全名与缩写