Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

PHP — Pipes Were Half a Feature Until Partial Application Arrived

--

Press enter or click to view image in full size

Write a PHP 8.5 pipe the way the pipe RFC’s own examples looked when it was voted on, and PHP refuses to run it:

Fatal error: Arrow functions on the right hand side of |> must be parenthesized

Fix that and the pipe works, but only nicely for functions that take one argument. Most useful functions take more than one, so on 8.5 a pipeline ends up as a column of wrapped arrow functions.

Here’s the honest version, up front. PHP 8.6’s partial function application fixes exactly that, and the result isn’t only shorter: the engine compiles it down to plain function calls, with no closure created at all. But I also counted, and in Laravel’s own source it would replace about 3% of closures. Partial application finishes the pipe operator; it doesn’t replace your closures.

Here’s what follows: one pipeline written three ways, what the engine actually does with each, three gotchas with real output, a count of Laravel and Symfony, and a six-step way to adopt it this week.

One pipeline, three PHP versions

The task is small and very PHP: turn ' php, Laravel ,,pipes, php ' into a clean, de-duplicated tag list. In 8.4 you read it inside-out:

// PHP 8.4: read it from the middle…

--

--

Dragan Rapić
Dragan Rapić

Written by Dragan Rapić

Sherlock of programming problems, Father of three & CTO @ Analitix.ai