I’m using __get and __set methods for variable overloading.
In some cases I will assign another object to a variable, for example:
$object->name->another = $another_object;
$object, has the __get and __set methods. When I try to access $object->name->another before it’s been set, I get the error
Notice: Trying to get property of non-object
Is there anyway around this using overloading? without having to check isset on the variable.
Thanks!
Not
$objectbut$object->nameneeds to have the overloading with__get()/__set()if you want to interact to prevent the error in question:For example you can make
$object::__get()return an emptystdClassobject, PHP would then automatically assign a public member to it in this case.