Will isset() trigger __get and why?

前端 未结 5 1750
面向向阳花
面向向阳花 2021-01-02 05:33
class a {
   function __get($property){...}
}

$obj = new a();
var_dump(isset($obj->newproperty));

Seems the answer is nope but why?

5条回答
  •  孤街浪徒
    2021-01-02 06:06

    No, __get should not be triggered when you're trying to determine whether a property is set : testing if a property is set is not the same thing as trying to get its value.

    Using isset triggers the __isset magic method.

    See :

    • isset
    • and Overloading

提交回复
热议问题