Since the beginning of this week, we've had a number of reports from Bolt developers who were getting the following errors after running a Composer update:

Parse error: syntax error, unexpected ':', expecting ';' or '{' in
/foo/…/Doctrine/Common/Cache/FileCache.php on line 220

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

Exception trace:
 () at /foo/…/Doctrine/Common/Cache/FileCache.php:220

This error happens because the Doctrine project have updated the minimum requirement of their libraries to PHP 7.1 in their latest update.

If you have a deploy process where you run composer update on the Development environment with one version of PHP, and composer install on Production with an earlier version of PHP, this sudden change might catch you off-guard.

Regardless of our opinion that this aggressive push for PHP 7.1 as a minimum requirement in a minor version update is disrespectful and irresponsible to users of the Doctrine libraries and projects that utilise them, it is out there and it is something we have to deal with.

Thankfully, we can take measures to prevent breakage on your projects. In short, there are three solutions, in order of our recommendation:

  1. Make sure your Development and Production environments run the same versions of PHP, whether it's PHP 7.1, 7.0, or all the way down to PHP 5.5

  2. Specify the target PHP version in your composer.json file, e.g.

    "config": {
        "platform": {
            "php": "5.5"
        }
    }

After doing so, run composer update to get the correct versions of packages. Be sure to omit the --ignore-version-reqs flag, because using that will override these settings.

  1. Edit your composer.json, to lock the Doctrine versions on a per project basis, depending on your lowest PHP version used
  • For PHP 5.5 or 5.6:

    "require": {
        "php": "^5.5.9 || ^7.0",
        "bolt/bolt": "^3.3@RC",
        "passwordlib/passwordlib": "^1.0@beta",
        "doctrine/annotations": "1.2.*",
        "doctrine/cache": "1.6.*",
        "doctrine/collections": "1.3.*",
        "doctrine/common": "2.6.*",
        "doctrine/dbal": "2.5.*",
        "doctrine/inflector": "1.1.*",
        "doctrine/lexer": "1.0.*"
    },
  • For PHP 7.0:

    "require": {
        "php": "^5.5.9 || ^7.0",
        "bolt/bolt": "^3.3@RC",
        "passwordlib/passwordlib": "1.0@beta",
        "doctrine/annotations": "1.4.*",
        "doctrine/cache": "1.6.*",
        "doctrine/collections": "1.4.*",
        "doctrine/common": "2.7.*",
        "doctrine/dbal": "2.5.*",
        "doctrine/inflector": "1.2.*",
        "doctrine/lexer": "1.0.*"
    },
comments powered by Disqus