On 10/03/2019 20:19, Dan Ackroyd wrote:
I believe those two parts of the RFC are completely possible already
in user-land with a trait similar to the one below. What would be the
compelling case for making it be a keyword, rather than the user-land
implementation that is already achievable?
Hi Dan,
Yes, such a trait had occurred to me before. My main motivation for
proposing it as part of the language is to make it as easy as possible
to opt into, and standardising the mechanics - I can see "all classes
must be strict" making it into far more coding standards than "all
projects must include this Trait and add it to all classes". It occurred
to me that language support might also allow optimisation around it,
whereas implementing __get()/__set() would likely do the opposite.
Apart from that, I was partly just experimenting with how hard it would
be to add; the answer, so far at least, is surprisingly easy.
The alternative would be to simply deprecate dynamic property getting
and setting altogether. I suspect that would affect a lot of code,
though, so would be wary of actually removing it as soon as PHP 8, given
that the set part doesn't even raise a notice right now.
and now this RFC (or at least 2/3 of it) could be implemented by
adding some traits by default to all classes in a package.
This wasn't really relevant to my motivation - you'd still have to add
it to each class under the proposed RFC - but it is an interesting idea.
In general, I think such packages would be a great addition to the
language, but they'd also be a big change in how things work, and take a
lot of working out, so I'm not going to hold my breath.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php