1

I try to run Yii2 app on apache server with 7.0 php version. Yii2 framework package version:

yiisoft/yii2                        3.0.x-dev 9f215f3

So, when I run my site.loc index page in the browser, I get an error

Parse error: syntax error, unexpected '=' in /var/www/html/remi-web.co/vendor/yiisoft/yii2/di/Container.php on line 365

The piece of code which cause an error:

 /* @var $reflection ReflectionClass */
    [$reflection, $dependencies] = $this->getDependencies($class);

An array[] in the left side of equing statement. I have been never faced with this kind of statement before, so I don't even know where to look for explaining.

I have just install php7.0 on Apache so maybe it needs some module installed or some property enable in settings to run it properly.

There is part of phpinfo details:

PHP Version 7.0.33-23+ubuntu18.04.1+deb.sury.org+1
Loaded Modules  core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_mime prefork mod_negotiation mod_php7 mod_reqtimeout mod_rewrite mod_setenvif mod_status 

It works on production server with PHP Version 7.0.32, but doesn't work on my local machine.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Valik Tralik
  • 69
  • 1
  • 12
  • 1
    Using [] is introduced in PHP 7.1 (https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.symmetric-array-destructuring) – Nigel Ren Mar 20 '20 at 13:55

1 Answers1

3

Since PHP 7.1 we have destructuring assigment of arrays.

[$x,$y] = [1,2];
echo $x;  // gives 1

This is shorthand for list():

list($x,$y) = [1,2];
echo $x; // gives 1

You can read about that PHP 7.1 feature here.

WeSee
  • 3,158
  • 2
  • 30
  • 58
  • This feature was first available with PHP 7.1.0 on 01 Dec 2016. Maybe check your PHP version again where the code works. Here is the PHP CHANGELOG reference: https://www.php.net/ChangeLog-7.php – WeSee Mar 20 '20 at 14:44