Re: [RFC] Default expression

From: Date: Tue, 27 Aug 2024 15:03:40 +0000
Subject: Re: [RFC] Default expression
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-125323@lists.php.net to get a copy of this message
> On Aug 27, 2024, at 10:14, Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk> wrote: > > The only expressions that are in some sense "safe" are those that can apply equally > to any possible type that the function could in future set as the default. In theory, that includes > a match statement with an arm of "default => default", e.g. > > json_encode($data, default, match(gettype(default)) { 'int' => default | > JSON_PRETTY_PRINT, default => default }); > > Apart from being incredibly hard to read, that's not even useful: the aim is to always > enable pretty printing, but the result is "enable pretty print, unless the type of the default > happens to change". I'm not sure this could even work at all. The "default" parameter to gettype() isn't the default value of the third parameter to json_encode(). It's the default value of the first parameter to gettype(). Which would probably fail, since gettype()'s first parameter doesn't have a default. I suppose this could be solved by specifying an offset or label (e.g. as with continue 2 in a nested loop), but that would just make it even harder to read. -John

« previous php.internals (#125323) next »