Re: [RFC] Pipe Operator (again)

From: Date: Mon, 10 Feb 2025 10:04:32 +0000
Subject: Re: [RFC] Pipe Operator (again)
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

Am 2025-02-07 05:57, schrieb Larry Garfield:

After also having taken a look at the implementation and then the updated “Precedence” section, I'd like to argue in favor of moving |> to have a higher precedence than the comparison operators (i.e. between string concatenation and <). This would mean that |> has higher precedence than ??, but looking at the following examples, that appears to be the more useful default anyways.

I'm rather interested in handling a null pipe result:

    $user = $request->get('id')
        |> $database->fetchUser(...)
        ?? new GuestUser();
Than handling a null callback (using the RFC example, because I can't even think of a real-world use-case):
    $res1 = 5
        |> $null_func ?? defaultFunc(...);
To give some more examples of what would be possible without parentheses then:
    $containsNotOnlyZero = $someString
        |> fn ($str) => str_replace('0', '', $str)
        |> strlen(...)
0; Which is not particularly pretty, but appears to be more useful than either passing a boolean into a single-argument function or piping into a boolean (which would error). Best regards Tim Düsterhus

Thread (42 messages)

« previous php.internals (#126366) next »