Re: [RFC] [Discussion] Readonly Classes
| From: | Michał Marcin Brzuchalski | Date: | Mon, 22 Nov 2021 17:47:29 +0000 |
| Subject: | Re: [RFC] [Discussion] Readonly Classes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116476@lists.php.net to get a copy of this message | ||
Hello Máté,
pon., 22 lis 2021 o 17:14 Máté Kocsis <kocsismate90@gmail.com> napisał(a):
> Hi Internals,
>
> I'd like to propose adding support for readonly classes:
> https://wiki.php.net/rfc/readonly_classes
>
> The implementation heavily builds on the semantics of the already accepted
> readonly properties RFC (https://wiki.php.net/rfc/readonly_properties_v2),
> basically the only thing I had to implement in the PR are the following:
> - Any declared property of a readonly class is implicitly treated as
> readonly
> - Creation of dynamic properties is forbidden
>
Personally, I'm not convinced at all about this idea.
The read-only property for me is a preliminary step before introducing
full-blown property/field accessors.
Instead of making the whole class readable I'd rather see sort of data
classes similar to record classes in other languages where you get
pass-by-value, built-in object initializer and class composition over
inheritance like Go structs.
But regardless of what I'd love to see this feature, I see no justified use
case.
Therefore I ask if there are any real use cases of it? and if there are
other languages with similar functionality?
Cheers,
Michał Marcin Brzuchalski