棘轮服务器实例化:“不支持的声明'strict_types'”; [英] Ratchet server instantiation: "Unsupported declare 'strict_types'"

查看:264
本文介绍了棘轮服务器实例化:“不支持的声明'strict_types'”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Windows本地计算机上运行的棘轮应用程序,其PHP版本为 7.1.8

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

我试图在 PHP版本5.5.9 zmq安装版本: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>

这是 composer.json文件的一部分

"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"
},

最小稳定度: dev

"minimum-stability": "dev"

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;
}

并与其他两个文件类似,包含以下内容: declare(strict_types = 1)

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

PHP版本似乎可以与 eventement / eventement 包一起使用因为

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"
        },

应该可以在上运行php> = 5.4.0 ,我们在服务器上有 php5.5.9

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.

推荐答案

您似乎已安装 evenement / evenement :3.0 ,需要PHP > = 7.0 。我猜您正在使用与运行您的PHP版本不同的PHP版本更新依赖项应用程序。如果使用PHP 7.1运行 composer update ,它将安装可在PHP 7.1上运行的依赖项。我建议配置您的 composer.json 平台 c $ c>强制安装PHP 5.5的依赖项,而与本地PHP版本无关。

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"
    }
},






Y您也可以在应用程序的 composer.json 约束中禁止 evenement / evenement:3.0 -安装3.0行不会如果您希望您的应用程序在PHP 5上运行,则很有意义:


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:您知道PHP 5.5.9真的很旧,不再支持5.5行吗?您至少应该真正升级到PHP 5.6。

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.

这篇关于棘轮服务器实例化:“不支持的声明'strict_types'”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆