Fluent Function

<?php

function WTF($arg) {
    // Payload: count the number of its own calls
    global $c;
    ++$c;

    // payload could be anything
    // use global to extract values
    global $collection;
    if (!isset($collection)) { $collection = []; }
    $collection[] = $arg;

    // also possible
    // $r = __FUNCTION__;
    // return $r(...)

    return __FUNCTION__;
}

WTF(1)(2)(4)(8)(16);

echo "WTF was called $c times
";
print_r($collection);

?>

A fluent interface allows the chaining of method calls. It is a bit harder to do with functions, as there is no supporting object, but it is possible.

Returning __FUNCTION__ allows the subsequent call of the same function.

Returning a closure of itself is also possible, yet a bit more cumbersome, as __FUNCTION__ is not recognized as a string for a function call.

Thanks to Andreas Heigl for the inspiration.

See Also

PHP Features

Last updated: 14 July 2026