Re: Proposal. Pipeline assignment operator

From: Date: Tue, 22 Jul 2025 22:33:33 +0000
Subject: Re: Proposal. Pipeline assignment operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-128186@lists.php.net to get a copy of this message
Hi

Am 2025-07-20 21:31, schrieb Vadim Dvorovenko:
In fluent we even can write foo()->bar()->baz()->assignTo($x) (as it's user-defined method, we can make any logic). With fluent we do not need nor pipe, nor ltr-assignment. But someone thought fluent syntax is not good, as this is not native language operator, but a wrapper pattern, and we have pipe operator now.
FWIW: You can also define such an assign_to() function for use with pipes. See https://3v4l.org/R5b2f/rfc#vgit.master:
    function assign_to(&$var) {
        return function ($value) use (&$var) {
            $var = $value;
        };
    }
    $string = "Hello World!";
    $string
        |> strtolower(...)
        |> ucfirst(...)
        |> assign_to($result);
    var_dump($result);
Best regards Tim Düsterhus

Thread (6 messages)

« previous php.internals (#128186) next »