phpilluminate-container

What's the PHP syntax for statement [$var1, $var2] = someMethod();?


I'm trying to get Illuminate/Database working on my PHP app and it's complaining on multiple occasions about code in the library that looks like this:

[$value, $key] = static::explodePluckParameters($value, $key);

And here's the error from the webserver:

Parse error: syntax error, unexpected '=' in /home/vol1_1/epizy.com/epiz_24040130/file-planner-rg.epizy.com/htdocs/vendor/illuminate/support/Arr.php on line 388

I managed to solve the previous instance where this occured by using an older version of the library (currently 5.7 as per my composer.json version constraint).

I've tried searching for this but not exactly sure what the variables between brackets represent in PHP. This is for a coding school I'm trying to get into.


Solution

  • [$variable1, $variable2] = someCall(); is a short syntax for array deconstructing assignment. It was introduced with PHP 7.1. You might have an older version. Using list() should work:

    list($value, $key) = static::explodePluckParameters($value, $key);