Support __get for getAttribute#4725
Conversation
|
Adding this without any tests is a no-go to me. And AFAIK, we already support dynamic properties (but it relies on |
|
@stof I wanted to make sure the implementation is finalized before doing any tests. The issue with __isset is that there is no difference between a null value and a "not defined" value. Would you consider adding an interface just for this? ie. This can be easily added to entities or other objects with dynamic properties. |
|
IIRC, this has been proposed several times in the past and using __isset() was the reason why we rejected the previous attempts. |
|
@fabpot Unfortunately __isset does not really distinguish between null and undefined, forcing us to use null coalescing and therefore defeating the reason we use strict variables in the first place. |
|
@nicosp it depends how you implement the method actually. |
|
@stof If you implement it correctly (per PHP spec) you will have to consider nulls as not set. I thought about using ArrayAccess::offsetExists but even then you have to follow this. See: https://bugs.php.net/bug.php?id=41727 Which is why I suggested the interface which would allow the implementation to be correct per PHP spec and still have Twig strict variables work properly. |
Allows object to use the __get magic function to fetch attributes.
This is very convenient when using Entities or other objects.
Ideally we can also use __isset to be more precise with defined checks but I am not sure.