PHP 8.5 Brings Long-Awaited Pipe Operator, Adds New URI Tools (theregister.com) 18
"PHP 8.5 landed on Thursday with a long-awaited pipe operator and a new standards-compliant URI parser," reports the Register, "marking one of the scripting language's more substantial updates... "
The pipe operator allows function calls to be chained together, which avoids the
extraneous variables and nested statements that might otherwise be
involved. Pipes tend to make code more readable than other ways to
implement serial operations. Anyone familiar with the Unix/Linux
command line or programming languages like R,
F#,
Clojure, or
Elixir
may have used the pipe operator. In JavaScript, aka ECMAScript, a
pipe operator has been proposed, though there are alternatives
like method chaining.
Another significant addition is the URI extension, which allows developers to parse and modify URIs and URLs based on both the RFC 3986 and the WHATWG URL standards. Parsing with URIs and URLs â" reading them and breaking them down into their different parts â" is a rather common task for web-oriented applications. Yet prior versions of PHP didn't include a standards-compliant parser in the standard library. As noted by software developer Tim Düsterhus, the parse_url() function that dates back to PHP 4 doesn't follow any standard and comes with a warning that it should not be used with untrusted or malformed URLs.
Other noteworthy additions to the language include: Clone With, for updating properties more efficiently; the #[\NoDiscard] attribute, for warning when a return value goes unused; the ability to use static closures and first-class callables in constant expressions; and persistent cURL handles that can be shared across multiple PHP requests.
Another significant addition is the URI extension, which allows developers to parse and modify URIs and URLs based on both the RFC 3986 and the WHATWG URL standards. Parsing with URIs and URLs â" reading them and breaking them down into their different parts â" is a rather common task for web-oriented applications. Yet prior versions of PHP didn't include a standards-compliant parser in the standard library. As noted by software developer Tim Düsterhus, the parse_url() function that dates back to PHP 4 doesn't follow any standard and comes with a warning that it should not be used with untrusted or malformed URLs.
Other noteworthy additions to the language include: Clone With, for updating properties more efficiently; the #[\NoDiscard] attribute, for warning when a return value goes unused; the ability to use static closures and first-class callables in constant expressions; and persistent cURL handles that can be shared across multiple PHP requests.
URI parser? (Score:1)
PHP didn't have a URI parser?
Re: (Score:2)
It most certainly did. The summary even discusses it.
Re: (Score:1)
Well, it's really more because the stock one was broken.
What PHP needs (Score:2)
Re: (Score:1)
It has two.
Re:What PHP needs (Score:5, Funny)
Re: (Score:2)
And add it to core. Then they'll have four!
Re: (Score:2)
And then push it live. Now they'll have five!
Re: (Score:2)
Presumably you mean the syntactic sugar we see in Perl and Javascript. Just something less cumbersome than preg_match('/pattern/',$input,$matches,$limit,$flags). And perhaps a regex compile facility like python has, though
PHP I imagine already optimises the case where the pattern is a literal string, so it knows it only has to compile it once
during parsing.
Re: (Score:2)
Presumably you mean the syntactic sugar we see in Perl and Javascript. Just something less cumbersome than preg_match('/pattern/',$input,$matches,$limit,$flags).
Indead.
one problem thou (Score:2)
2014 called?? (Score:3)
TFS doesn't even mention Java in its "anyone familiar with" list, but Java streams have been around since 2014 and are much a more disciplined and formal implementation of a very similar concept of chaining operations together like this. I'd call this Python pipe operator nothing more than syntactic sugar. Seriously, honest question...does it actually do anything functional other than change the *syntax* of how you chain calls together?
Survivor (Score:2)
I could not tell you one line of PHP in 2025, though I learned enough in 2004 to write a ticket-sales application with a database. It was for one event, so I picked the famously awful, kludgy, just-for-duct-tape language to get 'er done fast, never need to be maintained.
I have to admit, those calumnies against PHP have faded over the years, and here we are, >20 years later. Some 20 years earlier, I had learned PL/1 at University, the language of our MULTICS mainframe. It was predicted to take over