-3

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
askepott
  • 250
  • 3
  • 13
  • Point taken. What's with the downvotes anyway? It's a legit question is it not? – askepott Jun 19 '19 at 18:52
  • I haven't voted, and voting is anonymous, so I can only guess why people voted. Perhaps they were all frustrated at the request for urgency on a volunteer forum. Deadlines are particularly tricky in this regard - although people sympathise with tight deadlines, this particular formulation can be read as "if I don't get into coding school it is the fault of every reader who did not help", and that is extraordinarily coercive. – halfer Jun 19 '19 at 18:56
  • There are very few rules for up/downvoting: basically, people may vote for any reason as they like, and they may do it anonymously, as long as they do not vote by user. – halfer Jun 19 '19 at 18:58
  • Being that sensitive to a minor comment of little significance will not do well for an open community, imho. But thanks for your feedback, mate. – askepott Jun 19 '19 at 19:04
  • In general it's not about sensitivity, and we can't tell without personality tests and lie detectors. `;-)` We have thousands of questions coming in every day, and many of them are unanswerable or requests for someone to do their homework, etc. Most most new members who are here in earnest do not see this woeful stream. Old hands may now be happily trigger-happy in a small effort to turn the tide. It may help a bit, but that tide keeps on coming. You may have been caught in the cross-fire, but you now know what not to say `:-)`. – halfer Jun 19 '19 at 19:22

2 Answers2

2

Symmetric array destructuring was introduced in PHP 7.1 (which is the oldest version of PHP to still receive security updates; you should not be using anything older).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I'm using free hosting service InfinityFree which only has PHP 7.0. Fortunately, this is not a production app. :) – askepott Jun 14 '19 at 16:27
2

[$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);
ThW
  • 19,120
  • 3
  • 22
  • 44