Ratchet server instantiation: “Unsupported declare 'strict_types'”

一曲冷凌霜 提交于 2019-12-11 13:05:14

问题


I have a Ratchet application running smoothly in my windows local machine with PHP version: 7.1.8.

I tried to install zmq and php binding on linux deployment server with PHP version 5.5.9 and zmq installed version : 4.0.4.

Here's the error I get when I try to instantiate server script on server:

org@ktm /var/www/html/project_dir (pusher)$ php index.php "/report-test"

PHP Warning:  Unsupported declare 'strict_types' in /var/www/html/Test_Gbd_Portal/gbdportal-new/vendor/evenement/evenement/src/Evenement/EventEmitter.php on line 1
PHP Warning:  Unsupported declare 'strict_types' in /var/www/html/Test_Gbd_Portal/gbdportal-new/vendor/evenement/evenement/src/Evenement/EventEmitterInterface.php on line 1
PHP Warning:  Unsupported declare 'strict_types' in /var/www/html/Test_Gbd_Portal/gbdportal-new/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php on line 1
PHP Parse error:  syntax error, unexpected ':', expecting ';' or '{' in /var/www/html/Test_Gbd_Portal/gbdportal-new/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php on line 93
HTTP Fatal error: syntax error, unexpected ':', expecting ';' or '{' (GET /report-test)
<!DOCTYPE html>

Here's a part of composer.json file:

"require": {
"phpmailer/phpmailer": "5.2.9",
"phpoffice/phpexcel": "1.8.0",
"raveren/kint":"1.0.x-dev",
"jaspersoft/rest-client": "dev-master",
"cboden/ratchet": "dev-master",
"react/zmq": "dev-master"
},

"minimum-stability": "dev"

And composer.lock:

"name": "react/zmq",
        "version": "dev-master",
        "source": {
            "type": "git",
            "url": "https://github.com/friends-of-reactphp/zmq.git",
            "reference": "13dec0bd2397adcc5d6aa54c8d7f0982fba66f39"
        },
        "dist": {
            "type": "zip",
            "url": "https://api.github.com/repos/friends-of-reactphp/zmq/zipball/13dec0bd2397adcc5d6aa54c8d7f0982fba66f39",
            "reference": "13dec0bd2397adcc5d6aa54c8d7f0982fba66f39",
            "shasum": ""
        },
        "require": {
            "evenement/evenement": "^3.0 || ^2.0",
            "ext-zmq": "*",
            "php": ">=5.4.0",
            "react/event-loop": "^1.0 || ^0.5 || ^0.4"
        },
        "require-dev": {
            "ext-pcntl": "*",
            "phpunit/phpunit": "~4.8.35 || ~5.7 || ~6.4"
        },
        "type": "library",
        "autoload": {
            "psr-4": {
                "React\\ZMQ\\": "src"
            }
        },

In these files are where the problem seems to be:

vendor/.../src/Evenement\:
<?php declare(strict_types=1);

namespace Evenement;

class EventEmitter implements EventEmitterInterface
{
    use EventEmitterTrait;
}

and similar with other two files contain this: declare(strict_types=1).

PHP version seems to be okay with eventement/eventement package since

"require": {
            "evenement/evenement": "^3.0 || ^2.0",
            "ext-zmq": "*",
            "php": ">=5.4.0",
            "react/event-loop": "^1.0 || ^0.5 || ^0.4"
        },

it is supposed to work on php >=5.4.0 and we have php5.5.9 on server.

I cannot figure out what the problem is.


回答1:


It looks like you have installed evenement/evenement:3.0, which requires PHP >=7.0. I would guess that you're updating your dependencies using different PHP version than used for running your app. If you run composer update using PHP 7.1, it will install dependencies that works on PHP 7.1. I suggest to configure platform in your composer.json to force installing dependencies for PHP 5.5 regardless of local PHP version.

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

You can also disallow evenement/evenement:3.0 in constraints of composer.json of your app - installing 3.0 line does not make much sense if you want your app to run on PHP 5:

"evenement/evenement": "^2.0"

But using platform is more reliable - this issue may return for other packages too, and managing this manually can be real pain.


BTW: You know that PHP 5.5.9 is really old and 5.5 line is no longer supported? You should really upgrade to PHP 5.6 at least.



来源:https://stackoverflow.com/questions/52176996/ratchet-server-instantiation-unsupported-declare-strict-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!