class a
{
function __get($property){...}
}
$obj = new a();
var_dump(isset($obj->newproperty));
Seems the answer is nope but why?
class a
{
function __get($property){...}
}
$obj = new a();
var_dump(isset($obj->newproperty));
Seems the answer is nope but why?
The magic function __get is only called when you try to access a property that doesn't exist. Checking whether a property exists is not the same as retrieving it.
Because it checks __isset rather than retrieving it using __get.
It is a much better option to call __isset, as there is no standard on what is empty. Maybe in the context of the class null is an acceptable value. You could also have a class that if the member didn't exist, it returned a new empty object, which would break isset($myObj->item)
as in that case it would always return true.
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