周梦康 发表于 2018-08-13 1143 次浏览 标签 : 未完成
class foo{

    public function __construct($array = [])
    {
        if (!empty($array)) {
            $maps = get_object_vars($this);
            foreach ($array as $k => $v) {
                if (key_exists($k,$maps)) {
                    $this->$k = $v;
                }
            }
        }
    }

    public function test($a,$b){
        var_export($a,$b);
    }
}


class boo extends foo{

    public $a;
    public $b;

    /**
     * 没问题
     * boo constructor.
     * @param $a
     */
    public function __construct($a)
    {
        $this->a = $a;
    }
}

class xoo extends foo{
    /**
     * 报错
     * Warning: Declaration of boo::test($a) should be compatible with foo::test($a, $b)
     *
     *
     * @param $a
     */
    public function test($a){
        var_export($a);
    }
}

$boo = new boo(1);
var_export($boo);
$xoo = new xoo();
$xoo->test(1);

评论列表