Re: [RFC] [VOTE] Sealed Classes

From: Date: Thu, 17 Mar 2022 13:36:48 +0000
Subject: Re: [RFC] [VOTE] Sealed Classes
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-117354@lists.php.net to get a copy of this message
On Thursday, March 17th, 2022 at 11:38 AM, Nicolas Grekas <nicolas.grekas+php@gmail.com> wrote: > Le jeu. 17 mars 2022 à 04:54, Saif Eddin Gmati azjezz@protonmail.com a > > écrit : > > > Hello Internals, > > > > As per my last email in the previous thread, i have started the vote for > > > > sealed classes feature. > > > > The vote will run for 2 weeks until March 31st 2022. > > > > Discussion: https://externals.io/message/117173 > > > > Draft Discussion: https://externals.io/message/114116 > > > > RFC: https://wiki.php.net/rfc/sealed_classes > > Hello Saif, > > Thanks for the RFC. > > I voted "no" because to me this closes extensibility in a hard way. If > > users are fine ignoring an "@internal" annotation, or using reflection to > > access private symbols, then I think that's fine: their problem; they know > > why they need to do so - not authors. Allowing authors to forcibly remove > > that capability from users is going too deep into removing power from users. > > Said another way, I don't think this solves any problem that authors face > > in practice. As such I don't think this is worth the added language > > complexity + removal of power. > > Cheers, > > Nicolas Hello Nicolas, > to me this closes extensibility in a hard way. This is not necessarily true, we have final in PHP which does exactly that, but sealed can still allow for extensibility, just from a different point, e.g: ``` sealed interface Option permits Some, None { } interface Some extends Option {} interface None extends Option {} ``` In this example, both Some and None are open for extension, but Option is closed for any type aside from Some and None. > I don't think this solves any problem that authors face in practice It does! Considering the Option/Some/None example above, given Option, now you are sure that it's either an instance of Some or None, where previously, a third type could exist. Authors previously got around this issue by adding methods on Option such as isSome()/isNone()/isSuccess()/isFailure() .. etc reference: https://github.com/azjezz/psl/tree/2.0.x/src/Psl/Result Having sealed classes, ensures that there can't be a third type at runtime, and makes the is*() methods absolute, as now you can check the instance type. Regards, Saif.

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#117354) next »