Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EbrahemSamer's avatar

Declare Multiple Variables in PHP ?

I've downloaded php package and I found this syntax wihch cause an error

-------

[$variable1, $variable2] = $this->someMethod();

is this valid in PHP, What does it mean ?

0 likes
1 reply
automica's avatar
automica
Best Answer
Level 54

@ebrahemsamer its valid in php7.

what you see there is the short form of the list method. $this->someMethod() returns some variables and the first two are then defined as $variable1 and $variable2.

equivalent to

list($variable1,$variable2) = $this->someMethod()

IIRC that went in to PHP from 7.1. If you are getting an error, you may not have that version.

see https://wiki.php.net/rfc/short_list_syntax

Post the error here if you want help debugging.

Please or to participate in this conversation.