The magic methods __set
, __get
, __isset
and __unset
only get called when accessing inaccessible properties. That means either private properties, protected properties (accessed outside of a child class) or properties which haven't been created.
Calling your internal variable $_name
instead of $name
, or setting $name
to private
or protected
instead of public
will fix your problem.
Note:
You should only use protected
properties or functions when they need to be accessible from an extending class - don't use it just because.