The question mark reserves one argument in a PHP 8.6 function call.
Internet / The story

PHP 8.6 lets a question mark hold a function argument for later

A ticket label shows how the new placeholder fits into a pipeline, and why a reusable function can keep yesterday’s separator even after the settings change.

GeekRadar3 min read

A support desk labels tickets by their place in a category tree. Given Audio / USB / Input, it wants two fields: the department, Audio, and everything below it, USB / Input. The separator and the two-field limit are the same for every ticket. Only the label changes. In PHP 8.6, released on November 19, a developer can express that rule in one line and leave a question mark where the next ticket goes.

$splitLabel = explode(' / ', ?, 2);

PHP calls this partial function application. The line creates a closure, a value that can be called like a function. At this point no string has been split. Calling $splitLabel('Audio / USB / Input') fills in the missing argument and runs explode. As the string function’s reference explains, a positive limit of two keeps the rest of the string together in the second element. The extra slash survives, so someone answering the ticket still knows where under Audio it belongs.

The splitter takes the label as its second argument. A limit of two keeps USB / Input together.
The splitter takes the label as its second argument. A limit of two keeps USB / Input together.

Why the middle argument matters

PHP 8.5 introduced the pipe operator, written |>. It takes a value on the left and passes it to a callable on the right. That works neatly when a function needs just one input. A string splitter is a more interesting case. The string you want to pass is the second argument of explode; the separator comes first. A pipe alone has no way to pick the middle slot.

With the 8.6 placeholder, the point where the label enters is visible in the call. If labels arrive with stray spaces, the whole operation can read in the same order as the work:

$parts = '  Audio / USB / Input  '
    |> trim(...)
    |> explode(' / ', ?, 2);

The first stage trims the ends. The second receives the cleaned label in the slot marked ?. A team that supports PHP 8.5 can still write this as a pipeline by wrapping the split in an arrow function. The new spelling requires 8.6 wherever that file is parsed. That makes the version of the interpreter actually serving requests worth checking, a distinction that also mattered in GeekRadar’s earlier coverage of PHP updates.

When the separator is decided

One detail can change the result of a rewrite. Suppose the separator comes from a function called activeSeparator() because different feeds use different conventions. In explode(activeSeparator(), ?, 2), PHP looks up the separator when it creates the closure. Ten thousand subsequent labels use that same value. Put the lookup inside the body of an arrow function instead, and PHP calls it each time a label arrives. The language manual documents the evaluation rule.

For a batch from one feed, fixing the separator up front is exactly what you want. If the feed can switch halfway through, create a new splitter at the switch or choose the separator per ticket. The question mark tells you what can change on the next call. In a long-running import, the more interesting question may be which values you just agreed to keep.