Re: [RFC] Default expression

From: Date: Mon, 26 Aug 2024 17:35:02 +0000
Subject: Re: [RFC] Default expression
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-125278@lists.php.net to get a copy of this message
> From the example you gave it appears that we can have a concrete problem when: > 1. There is a parameter with a default value, > 2. That parameter is type-hinted, > 3. The hinted type is declared as a union type, > 4. An earlier version of the library initialized the default with a value having one of the > union types, > 5. End-user developers used the library and then use default as > an expression of that type, and finally > 6. The library developer changed the initialization of the > default to a different type from the union. > > Did I correctly identify the problematic use-case? Not really. #2 and #3 are irrelevant mixed is actually much more problematic, I wanted to provide an example that was strongly typed intentionally to show the problem even when types were explicit. The relevant portion is #1, #5 and #6. > Ok, so for argument sake, what if they revise the RFC to only allow default!ÊÍ > =ÇCj?¤z¼³¨( to be used in an expression when the parameter is not type-hinted with a union? Would > that address your concern? Or are there other use-cases that are problematic that do not hinge on > the parameter being type-hinted as a union type? It wouldn't be enough, offhand it'd also have to be forbidden for mixed (at which point I think the utility isn't there anymore).

« previous php.internals (#125278) next »