I've never been a fan of this kind of magic, and I wonder how other languages deal with this case.
self.__dict__['property_name']
And if those PHP rules were in python you could just write: @property
def property_name(self):
return self.property_name
In actual python though, that would infinitely recurse.var milliseconds: int = 0
var seconds: int:
get:
return milliseconds / 1000
set(value):
milliseconds = value * 1000https://learn.microsoft.com/en-us/dotnet/csharp/programming-...
It's pretty similar to what PHP provides here, except that PHP uses "$this->propname =" and C# uses "field =".
Edit: As someone involved in the RFC, it's somewhat funny, because we considered a special variable like "$field" or "$value" too magic, and C# does just that with a field keyword.
I used it in Unity projects to have serialized/inspectable values exposed through properties:
[field: SerializeField]
public int MyProperty { get; private set; }edit: the properties reference now documents the 'field' keyword too
In fact, you can imagine what their argument WOULD have been if setting `$this->countryCode` inside the setter for `countryCode` DID result in infinite recursion.
When it comes to PHP, whatever it does, on HackerNews and in the rest of the industry, it just results in a bunch of people complaining about it. Disappointing, and unprofessional.
Though what would you personally call "the thing that turns it into bytecode"?
Conversely php already has other places where context affects property accesses, and IME it's not the problem you make it out to be.
The backing value is effectively private to everything but its own get/set methods, that seems fairly straightforward to me.