2 ms·
8.5 notably includes the new pipe operator: https://stitcher.io/blog/pipe-operator-in-php-85 https://stitcher.io/blog/pipe-operator-in-php-85
by moebrowne 1y ago
8.5 notably includes the new pipe operator: https://stitcher.io/blog/pipe-operator-in-php-85 https://stitcher.io/blog/pipe-operator-in-php-85
- HackerThemAll 1y agoGreat news! PHP is going to humiliate all its haters.
- kriz9 1y agoI feel like if you treat temporary variables as documentation they feel less icky. All these examples with the pipeline operator cause way more mental overhead than reading temporary variable names.
- V__ 1y agoI think it really depends on what operations you are applying. Having one succinct named variable like $slug with a few simple pipeline calls like in the example is "self-documenting" and easy to read. However, some lambdas and non-standard function are definitely a place for nicely named temporary variables in my opinion.
- xdfgh1112 1y agoKind of a clunky and verbose syntax at the moment. I wonder what languages get pipe syntax right? Obligatory: Raku supports pipe in both directions, passing input as the last parameter instead of requiring the function to take only one parameter. It also has a shorthand: my @array = <7 8 9 0 1 2 4 3 5 6 7 8 9>; my @final-array = @array.unique.sort.reverse; say @final-array;
- moebrowne 1y agoThere is a complementary Partial Function Application RFC which, among other things, solves the one-parameter limitation. It allows a question mark to be substituted in for the piped value: $foo |> str_replace('hello', 'hi', ?); https://wiki.php.net/rfc/partial_function_application_v2 https://wiki.php.net/rfc/partial_function_application_v2
- tslocum 1y agoBased on the examples given in the blog post, this appears to be a massive step backwards for PHP. The language has been making an effort to clean itself up for years. The author claims that the temporary variable solution "feels icky". If we ultimately care about readability and performance, temporary variables seem ideal even with this change in the language. Modern compilers look for things like temporary variables when performing optimizations. PHP's compiler probably already does this, and if it doesn't, adding support for that would make more sense than adding some new syntax.
- phendrenad2 1y agoI'm not complaining, and I respect the PHP team for continuing to try to improve the language, but I think that we might have passed the point where new additions to the language actually make it worse.