Hacker News new | ask | show | jobs
by wvenable 576 days ago
I'm not a fan of that kind of magic in my languages but such a thing was already easily doable in PHP. You could just have a base class that implements __get and __set so that $this->foo automatically calls $this->getFoo().
1 comments

can't do that if you declare the properties on the class. __get only works for undefined properties.
Well don't do that then. :)
That advice doesn't always work in real life; otherwise for every compiler or linter check in any language, we could drop all those checks and tell the programmers not to do that.

E.g. if a base class declares a variable it can potentially break its children. Whose at fault here?

I agree with your original comment though. And if the bypass of exisitng fields is badly wanted, somehow marking __get to disregard them makes more sense to me.

Or, alternatively, use `__call`
Doctor, doctor, it always hurts when I press here…