Re: [Early Feedback] Pattern matching

From: Date: Mon, 24 Jun 2024 09:31:36 +0000
Subject: Re: [Early Feedback] Pattern matching
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Mon, Jun 24, 2024 at 7:04 AM Hendra Gunawan
<[email protected]> wrote:
>
> I agree that this proposal should be proposed as a whole. If we break
> it down into smaller parts, there is a chance some features will not
> pass.

This is exactly my concern and I fear we will be dealing with the
repercussions of a non-well-thought-out sub-feature for years to come.

Why does new Pattern() have the ability to accept patterns as a
parameter? Can other code do that as well? Why is @($thing) a thing? @
is already an operator so seeing it used like this is strange. Same
with ~ . It's also weird to see ? on the left hand side of a
literal.

PHP already has variable-variables, so use those instead of @(): $foo
is $$mypattern.

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.

~ has no meaning in mode 0, only in strict mode, but will force people
in mode 0 to work like they are in strict mode or litter their code
with ~'s. PHP is duck-typed and making it act like it isn't is just
bad DX. Further, it isn't clear how it will affect literals since it
is also bitwise-not.


Thread (79 messages)

« previous php.internals (#123780) next »