Re: [Early Feedback] Pattern matching

From: Date: Mon, 24 Jun 2024 15:56:51 +0000
Subject: Re: [Early Feedback] Pattern matching
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message

> On Jun 24, 2024, at 3:31 AM, Robert Landers <[email protected]> wrote:
> 
> 
> There's no need to use ? to check for existence on a key, so this:
> 
> $arr is ['a' => string, ?'b' => string, ...];
> 
> should be this:
> 
> $arr is ['a' => string, 'b' => ?string, ...];
> 
> because $arr['non-existent-key'] is NULL.
> 


The first means b is an optional key, but if it’s there, can only be a string. The second says b
is a required key, but it may be a string or null. If there were a binding involved, that determines
the type of the binding in incompatible ways.  I’m fine with requiring bindings to be nullable for
optional keys, but it strikes me as strictly less flexible and not consistent with the rest of
PHP’s behavior, at least not under E_ALL.

(Sorry for any dups.  juggling sender addresses to make the listserv happy, fixed an incomplete
thought while I was at it)

Cheers,
chuck


Thread (79 messages)

« previous php.internals (#123783) next »