←back to thread

PHP 8.5

(stitcher.io)
201 points brentroose | 1 comments | | HN request time: 1.39s | source
Show context
mg ◴[] No.45990447[source]
When I look at the new pipe syntax ...

    $output = $input
        |> trim(...)
        |> (fn (string $string) => str_replace(' ', '-', $string))
        |> (fn (string $string) => str_replace(['.', '/', '…'], '', $string))
        |> strtolower(...);
... I think why not just something like the following?

    $output = $input
        |> trim($)
        |> str_replace(' ', '-', $)
        |> str_replace(['.', '/', '…'], '', $)
        |> strtolower($);
replies(2): >>45990476 #>>45990939 #
1. Epskampie ◴[] No.45990476[source]
The three dots in trim(...) make a callable out of a function, that was already in, so seem best to re-use that syntax, at least for now. [1]

As for the partial function application, there is already an RFC to add that, but it's not decided on as of now. [2]

1: https://www.php.net/manual/en/functions.first_class_callable...

2: https://wiki.php.net/rfc/partial_function_application_v2