To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

php Magic methods __call

<?php
    class Car{
        protected $_color;
        protected $_model;

        public function __call($name,$arguments){
            $first=isset($arguments[0]) ? $arguments[0] : null;
            switch ($name) {
                case 'getColor':
                    return $this->_color;
                case 'setColor':
                    $this->_color=$first;
                    return $this;
                case 'getModel':
                    return $this->_model;
                case 'setModel':
                    $this->_model=$first;
                    return $this;
            }
        }
    }
    $car=new Car();
    $car->setColor("blue")->setModel("b-class");
    echo $car->getModel();
?>

 

posted on 2013-07-25 09:33  Ijavascript  阅读(201)  评论(0编辑  收藏  举报