Re: [PHP-DEV] [RFC] Deprecations for PHP 8.6

[email protected] (Tim Düsterhus)
Newsgroups php.internals
Message-ID <[email protected]>
Hi

Am 2026-07-02 05:51, schrieb Seifeddine Gmati:
>> `array_destruct()` that would address the readability argument (which 
>> is
>> hard to discuss away because it is hyper subjective).
> 
> This can't work, and not for stylistic reasons. Destructuring happens
> in a *write* context: the construct sits on the left of `=` and
> receives bindings. A function can't do that. `array_destruct($a, $b) =
> $arr` isn't expressible

That specific syntax would indeed not be possible, but the following 
would work:

     <?php

     function destruct(array $a, &...$results) {
         foreach ($results as $key => &$val) {
             $val = $a[$key];
         }
     }

     destruct([1, 2, 3, 'b' => 'b'], $a, b: $b);
     var_dump($a, $b);

see: https://3v4l.org/ia489n#veol

Best regards
Tim Düsterhus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.