Skip to content

PHP Fatal error: Cannot use list() as standalone expression #11320

Closed
@kubawerlos

Description

@kubawerlos

Description

The following code:

<?php

$index = 1;
function getList() { return [2, 3]; }

$a = [$index => list($x, $y) = getList()];

print_r($a);

Resulted in this output:

PHP Fatal error:  Cannot use list() as standalone expression in test.php on line 6

But I expected this output instead:

Array
(
    [1] => Array
        (
            [0] => 2
            [1] => 3
        )

)

This syntax is correct since PHP 5.4 up to 8.2.

Timeframe: it started to fail yesterday in PHP CS Fixer CI:

PHP Version

8.3.0-dev

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions