为什么当我重写魔术函数 __get 和 __set 时 isset 不返回 true

Che*_*eng 0 php

我有以下代码。

我可以知道,为什么当我重写魔术函数并且isset不返回 true 时__get__set

我得到的输出是

$param->country : US
isset($param->country) : 
Run Code Online (Sandbox Code Playgroud)
<?php

class Param
{
    private $params = array();

    public function __get($name) {
        return $this->params[$name];
    }

    public function __set($name, $value) {
        $this->params[$name] = $value;
    }
}

$param = new Param();
$param->country = "US";
echo "\$param->country : " . $param->country . "\n";
echo "isset(\$param->country) : " . isset($param->country) . "\n";
Run Code Online (Sandbox Code Playgroud)

dec*_*eze 5

__set并且__get不处理isset。您还必须实施魔术方法。__isset