不會(huì)啊 不懂 完全懵了 求大神詳細(xì)解釋一下
class Car {
? ?private $ary = array();
? ?
? ?public function __set($key, $val) {
? ? ? ?$this->ary[$key] = $val;
? ?}
? ?
? ?public function __get($key) {
? ? ? ?if (isset($this->ary[$key])) {
? ? ? ? ? ?return $this->ary[$key];
? ? ? ?}
? ? ? ?return null;
? ?}
? ?
? ?public function __isset($key) {
? ? ? ?if (isset($this->ary[$key])) {
? ? ? ? ? ?return true;
? ? ? ?}
? ? ? ?return false;
? ?}
? ?
? ?public function __unset($key) {
? ? ? ?unset($this->ary[$key]);
? ?}
}
$car = new Car();
$car->name = '汽車'; ?//name屬性動(dòng)態(tài)創(chuàng)建并賦值
echo $car->name;
2017-08-08
?你的ary是私有屬性,只能通過(guò)self等調(diào)用,不能用this調(diào)用