back to article PHP 8.5 lays down long-awaited pipe operator, adds new URI tools

PHP 8.5 landed on Thursday with a long-awaited pipe operator and a new standards-compliant URI parser, marking one of the scripting language's more substantial updates. PHP, short for Personal Home Page when initially released in 1995 by Rasmus Lerdorf, now stands for PHP: Hypertext Preprocessor. Version 8.5 is a major release …

  1. wolfetone Silver badge
    Pint

    Finally a proper URI parser!!!!!!!

    Have a pint for that alone!

  2. Charlie Clark Silver badge

    Good luck testing that!

    If I'm reading it correctly, that pipe example includes embedded lambda functions. That is not going to make testing any easier and one of the arguments against this approach to chaining, is that it makes testing harder. It also doesn't look like it's particularly memory efficient, which can be an unexpected Easter egg in this kind of thing, though it's possible the implementation caters for this.

    However, a functional approach to programming has its benefits, otherwise we wouldn't have it, but I find the implementation unusual.

    FWIW the Python approach in idiomatic expressivity and simplicity. Well I think so at least! ;-)

    import itertools

    a = ["a", "b", "c"]

    b = ["c", "d", "e"]

    c = ["x", "y", "a"]

    values = itertools.chain(a, b, c) # not yet evaluated

    result = set(values) # use a hash-table otherwise

    print(result)

    >>>{'y', 'e', 'b', 'a', 'x', 'd', 'c'}

    The pattern would hold true for many similar situations.

    May your language god and editor go with you.

    1. takno

      Re: Good luck testing that!

      I don't love the embedded lambdas on the face of it, if only because I don't really know what they are supposed to be doing at a first glance. I could probably get used to them though.

      The rest of your post seems to be confusing the new feature with iterators. That's a fair enough mistake to make, since the rather contrived comparison of the feature with shell pipes encourages it. This feature is really just syntactic sugar to better present a set of nested function calls. The semantics (and therefore memory usage) should be exactly the same as nested function calls.

      FWIW PHP has had iterator functionality for years which works in a similar way to itertools in Python. I find the Python syntax for it rather bewildering in comparison with other languages, primarily because it leans so heavily on global functions rather than class methods. Ironically this could be greatly improved if Python got a pipe operator. In fact when I first saw a pipe operator used in Elixir (don't ask), it seemed to mostly be there to make a functional language more readable.

      1. Charlie Clark Silver badge

        Re: Good luck testing that!

        I wondered about the example myself but went ahead with my own for sake of completeness. Often when you spell things out and add tests, other, simpler approaches become apparent.

        I don't mind the criticism at all – I very much like Python syntax but I know that many, for various reasons don't. I think there were attempts in the past to introduce shell-like features to Python, but they were not popular and print "" >>" or whatever it was not missed when it was removed.

  3. jezmck
    Meh

    Ceci n'est pas une pipe

    As a 20y+ user of PHP, I really don't see the problem with nesting function calls, it's just part of how some languages work.

    I'm aware it's optional, but since we use a lot of each other's work, it still has to be understood by everyone, and some people just want to use new/shiny things instead of what fits the scenario best.

    1. takno

      Re: Ceci n'est pas une pipe

      Nested function calls are just a huge amount more difficult to read and reason about. Pipe operators make reviewing and modifying code less painful - I'd be a happier developer if they were added to all the languages I used tomorrow.

      You can make an argument that PHP should be a maintenance-mode language at this stage, and that all the syntactic-sugar in the world is unlikely to stop its decline. I'd agree with that - having built a couple of significant startups on it, I'm extremely keen to never use it again and wouldn't be dragged back by all the quite-nice new features in the world. I've never forgiven them in any case for bowing to the short-lived fad of banning chained ternaries.

      The main thing though is that the syntactic sugar is what keeps people engaged in working on the core. That's the only way to make the language more secure and deal with some of the longer-standing issues. If the language was just left to stagnate then the internet would be a worse place for it.

  4. PRR Silver badge

    PHP is catching up to MS-DOS BAT language of the 1980s? Pipes and iteration? Maybe PHP proposes to do it better, but its 40 years later.

  5. Briantist69
    Facepalm

    point of **pipes** is split the task into separate CPU process - NOT Just to chain input-output

    I'm sorry but the whole point of **pipes** is split the task into separate (concurrent) CPU process

    Example

    cd ~/logs; tail -f *.log|grep -n 'error'|awk '{print $1}' &

    [1] 1501967

    ]$ ps

    PID TTY TIME CMD

    1501965 pts/0 00:00:00 tail

    1501966 pts/0 00:00:00 grep

    1501967 pts/0 00:00:00 awk

    1501975 pts/0 00:00:00 ps

    2144057 pts/0 00:00:00 bash

    As leant in 1980s

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon