user3599441
user3599441

Reputation:

Syntax error when trying to clear my Symfony project cache

When I try to clear the cache of my Symfony2.8 project, I get the following error:

[Symfony\Component\Debug\Exception\FatalErrorException] Parse Error: syntax error, unexpected '['

Here is more deParse error:

syntax error, unexpected '[' in /home/jack/html/fc/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 90

I upgraded my Symfony2.7 to 2.8 yesterday and now I am busy fixing deprecations to get it ready for version 3. I just though about clearing cache now and then, but I just got this error.

I used this command:

php app/console cache:clear

Upvotes: 1

Views: 2288

Answers (1)

chalasr
chalasr

Reputation: 13167

There is likely a problem coming from the PHP version used by the CLI while running the command.

The error is coming from the usage of [] as array declaration.
This short syntax has been introduced when PHP released its 5.4 version.

In a Symfony 2.7 fresh installation, the line that causes your bug looks like :

/**
 * @var \Doctrine\Common\Proxy\ProxyDefinition[]
 */
private $definitions = array();

In Symfony 2.8 :

/**
 * @var \Doctrine\Common\Proxy\ProxyDefinition[]
 */
private $definitions = [];

Also the error cannot come from somewhere else.

If your CLI version is really 5.6, you should be able to do run the following from your bash:

php -r '$array = []; var_dump($array);'
// output: array(0) {}

If you don't get any error, there is something in your project that conflicts with your real PHP version by disabling some features.

Otherwise, you have two options :

  • Downgrade Doctrine
  • Upgrade PHP

I hope this clarify the real problem.

Upvotes: 2

Related Questions