Hi

Am 2025-02-07 05:57, schrieb Larry Garfield:
https://wiki.php.net/rfc/pipe-operator-v3

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

Reply via email to