0

I did a composer update in my yii2 project and after that I'm getting syntax error, unexpected '?' in /vendor/symfony folder in several places dom-crawler etc. in yii2.

I'm only getting error while I'm opening form with yii2 dynamic form. The other view files are working fine.

composer.json file - 
{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.6",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "kartik-v/yii2-widget-sidenav": "*",
        "kartik-v/yii2-grid": "*",
        "2amigos/yii2-date-picker-widget": "~1.0",
        "kartik-v/yii2-widget-select2": "@dev",
        "reportico/yii2-reportico": "dev-master",
        "miloschuman/yii2-highcharts-widget": "*",
        "kartik-v/dependent-dropdown": "dev-master",
        "kartik-v/yii2-widget-depdrop": "@dev",
        "kartik-v/yii2-date-range": "*",
        "kartik-v/yii2-widget-activeform": "@dev",
        "yiisoft/yii2-jui": "^2.0",
        "kartik-v/yii2-widget-datetimepicker": "*",
        "kartik-v/yii2-widget-datepicker": "@dev",
        "kartik-v/yii2-field-range": "*",
        "wbraganca/yii2-dynamicform": "*",
        "yiisoft/yii2-debug": "^2.0",
        "mpdf/mpdf": "^6.1",
        "kartik-v/yii2-mpdf": "*",
        "beaten-sect0r/yii2-db-manager": "*",
        "spanjeta/yii2-backup": "*",
        "warrence/yii2-kartikgii": "dev-master",
        "kartik-v/yii2-export": "*"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*"
    },
    "config": {
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}

php version - 7.0.2

I tried to remove vendor directory, clear cache and composer install again with same result.

4
  • just remove the vendor directory and run composer install again Commented May 13, 2018 at 15:39
  • it uses symfony/dom-crawler and "symfony/css-selector": "~2.8|~3.0", that might be having trouble. you can verify by using composer show -i on project root, to look what is installed and which version Commented May 13, 2018 at 15:41
  • You're probably trying to use packages that require PHP 7.1 on pre-7.1 environment. Please share your composer.json content and your PHP version. Commented May 13, 2018 at 15:51
  • I've updated the question some more information. Commented May 13, 2018 at 15:58

2 Answers 2

2

First, you should lock your PHP version in composer.json config:

"config": {
    "platform": {
        "php": "7.0"
    }
}, 

It looks like you're using different PHP version for installing packages, so Composer is installing packages that require PHP 7.1. Adding this will force Composer to install versions for PHP 7.0.

Second, you should really avoid constraints like >=2.0.6, @dev or *. This will allow Composer to upgrade packages to new major version which may (and probably will) introduce backward compatibility break. So even if package will work on PHP 7.0, it may break your app.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, the colon after platform is shown as pink mark in sublime text.. And secondly, do we need a composer update after it.
Yes, you need to run composer update after this change. You may even need to delete vendor directory and composer.lock before update - composer-asset-plugin has known bug with downgrading packages.
You are a lifesaver. I spent more than 4 hours trying to find a way around this error until I came to your answer. Thanks, Worked like a miracle.
0

Try upgrading your php version. It worked with me.

2 Comments

From what, to what? Please explain
I'm getting syntax error, unexpected '?' in /vendor/symfony folder in several places dom-crawler etc. in yii2. His/Her question was somethimg like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.