Hello,
I am writing with PHP feature suggestion, regarding static information about class properties.
Now in PHP there’s a feature feature letting you access full class name statically (getting static class name via MyClass::class).
It’s very minimalistic but even that allows users to have one single point of truth for full class name.
My suggestions would be to create something similar for class properties f.e.
MyClass::properties::name could return “name” or some built-in meta data object of that property containing more information(type, nullable, public/private etc.).
As weird as it sounds - even returning the same “name” value would let IDE and libraries to get information more statically.
There are plenty of libraries that asks developers to use field names as strings. For example - Doctrine ORM, you need field names when defining relations or generating DQL queries. For classes you are using ::class syntax, but for fields you need to hardcode string values that are pain to refactor later on or to run static analysis.
I understand that whole idea is kind of abstract but I am sure that a lot of PHP developers who are targeting to write cleaner code would approve of something similar to this to help reduce hardcoded value in their code.
Let me know what you think. I could spend some time defining more specific documentation of how I would solve it, maybe write and RFC. My first idea was to write you, maybe there is similar ideas already reached you.
Vilius Buividavičius