3
マジックセッターを使用して設定されたプロパティが存在するかどうかを確認することはできますか?プロパティが存在するか確認する
class Test
{
private $vars;
public function __set($key, $value) {
$this->vars[$key] = $value;
}
public function &__get($key)
{
return $this->vars[$key];
}
}
$test = new Test;
$test->myvar = 'yay!';
if (magic_isset($test->myvar)) {
}
私のクラスでは別の機能を設定する必要はありませんか?
は__isset http://php.net/manual/en/language.oop5.overloading.php – Damp
@Damp Eeeckを見てみてください。 ofc。 :P \ – PeeHaa
@danjordanが言うように、実際にはphp5 +でのproperty_existsを試してみるよhttp://php.net/manual/en/function.property-exists.php –