# Uniform Function Call Syntax

- Thread: https://externals.io/message/127037
- Original archive: https://news-web.php.net/php.internals/127037
- Started by Yakov Lipkovich on 2025-04-04T01:52:01+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #127037 — Yakov Lipkovich — 2025-04-04T01:52:01+00:00

URL: https://externals.io/message/127037#127037

Hello,

I would like to gather interest in adding Uniform Function Call Syntax (UFCS) to the PHP language. In short, it allows to call any static function `f($a)` as `$a->f(...)`. The `...` is required because not all functions have the desired parameter in the first position. Outlined below are some benefits of this syntax.

It allows for chaining of function calls that otherwise would look ugly. A common pattern is filtering and mapping arrays:
```php
$arr = [1, 2, -3, 4, 0, 5];
$filtered = \array_filter($arr, fn ($x) => $x > 0);
$result = \array_map(fn ($x) => $x * 2, $filtered);
\var_dump($result);
```
This can be written more eloquently:
```php
[1, 2, -3, 4, 0, 5]
        ->\array_filter(..., fn ($x) => $x > 0)
        ->\array_map(fn ($x) => $x * 2, ...)
        ->\var_dump(...);
```

Another use case is for extension functions:
```php
class Cat
{
        public function __construct(public string $name) {}
       
        public function meow(): self
        {
                echo "{$this->name} meowed\n";
                return $this;
        }
       
        public function lickPaw(): self
        {
                echo "{$this->name} licked paw\n";
                return $this;
        }
}

class CatExtension
{
        public static function scratch(Cat $cat): Cat
        {
                echo "{$cat->name} scratched\n";
                return $cat;
        }
}

$cat = (new Cat('Tabby'))
        ->meow()
        ->(CatExtension::scratch)(...)
        ->lickPaw();
```

For my proposal, only static functions need to be supported, but I don't see why non-static functions can't be supported. One thing I'm unsure of is what happens if an imported static function has the same name as a member function.

The Wikipedia page has a bit more details, as well as examples of languages which implement this syntax: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax.

Please let me know your questions, opinions, and feedback.

Regards,

Yakov

---

## #127039 — Larry Garfield — 2025-04-04T04:40:32+00:00

URL: https://externals.io/message/127037#127039 · In reply to: #127037

> Hello,
>
> I would like to gather interest in adding Uniform Function Call Syntax 
> (UFCS) to the PHP language. In short, it allows to call any static 
> function `f($a)` as `$a->f(...)`. The `...` is required because not all 
> functions have the desired parameter in the first position. Outlined 
> below are some benefits of this syntax.

Welcome.

I recommend having a look at the Pipes thread[1], especially the last week or so of messages, where we're discussing something very close to this.  My most recent message touches on this as well toward the end.

In short, it's not realistic to "bolt on" such a universal approach to a language as mature as PHP.  However, using pipes, partial application, and/or extension functions we can get to something that feels very similar, and that's already being worked on.  (More details in that thread.)

Cheers.

--Larry Garfield

[1] https://externals.io/message/126318

---

## #127043 — tim@bastelstu.be — 2025-04-04T11:31:21+00:00

URL: https://externals.io/message/127037#127043 · In reply to: #127037

Hi

Am 2025-04-04 03:52, schrieb Yakov Lipkovich:
> One thing I'm unsure of is what happens if an imported static function 
> has the same name as a member function.

Larry already linked to the Pipe-Operator thread, which tries to solve 
something similar.

Nevertheless, I'd like to note that resolving this ambiguity between 
“method” and “free-standing function” is the most important part to 
solve *before* proposing UFCS and not just a small detail. Without that 
being resolved (or least without having an idea how to solve it), the 
UFCS proposal is just a “wishlist” entry and discussing wishlist entries 
without having an idea of how they are supposed work in practice is not 
particularly productive discourse. It's similar with generics, unless 
someone proposes a solution, just repeatedly stating that “PHP needs 
generics” is not bringing generics to the language.

Personally I have no idea how resolving the ambiguity would work, 
without making the uniform function call syntax non-uniform in practice.

Best regards
Tim Düsterhus
