What PHP 8.6 Brings: Simplified Function Calls Illustrated

The article previews PHP 8.6’s upcoming function‑argument placeholder feature and shows how it can replace a multi‑step pipeline of arrow functions with a concise slug‑generation snippet, making the code shorter and clearer.

21CTO
21CTO
21CTO
What PHP 8.6 Brings: Simplified Function Calls Illustrated

The author looks forward to the official release of PHP 8.6, noting that the new support for certain function features will be very useful.

Previous code (PHP 8.5 and earlier):

$output = $input
    |> trim(...)
    |> (fn (string $string) => str_replace(' ', '-', $string))
    |> (fn (string $string) => str_replace(['.', '/', '…'], '', $string))
    |> strtolower(...);

The pipeline relies on inline arrow functions to perform successive string replacements before converting the result to lower case.

Revised code after PHP 8.6:

$slugReplace = str_replace([' ', '_'], '-', ?);
$output = $input
    |> trim(...)
    |> str_replace(' ', '-', ?)
    |> str_replace(['.', '/', '…'], '', ?)
    |> strtolower(...);

In the updated version, a variable $slugReplace is defined using str_replace, and the pipeline uses a placeholder ? to pass arguments directly to functions, eliminating the need for intermediate arrow functions.

This new placeholder syntax shortens the code, improves readability, and demonstrates one of the practical benefits expected from PHP 8.6’s enhanced function support.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendcode refactoringPHPfunction argumentsPHP 8.6
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.