-
Don’t forget __isset() with overloaded setters and getters
This post is mostly a marker for me to find the solution for this problem in the future. What problem? Well, a call using
empty()to test a class field always returned true even if the field wasn’t empty.The reason for this behavior is that the class overloads
__set()and__get()to do some extra checking on the fields. But overloading these functions also effectsempty(). To makeempty()behave normally__isset()must also be overloaded to test the used fields.And when implementing
__isset()think about__unset(), maybe you need to overload it as well.The PHP Manual contains an example of overloading these magic members.
Laat een reactie achter