php - Ratchet 服务器实例化 : "Unsupported declare ' strict_types'"

标签 php composer-php zeromq ratchet

我有一个 Ratchet 应用程序在我的 Windows 本地机器上运行顺利,使用 PHP version: 7.1.8 .

我尝试使用 PHP version 5.5.9 在 linux 部署服务器上安装 zmq 和 php 绑定(bind)和 zmq installed version : 4.0.4 .

这是我尝试在服务器上实例化服务器脚本时遇到的错误:

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

“最低稳定性”:“开发”

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

在这些文件中,问题似乎出在:
vendor/.../src/Evenement\:
<?php declare(strict_types=1);

namespace Evenement;

class EventEmitter implements EventEmitterInterface
{
    use EventEmitterTrait;
}

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

PHP 版本似乎没问题 eventement/eventement包自
"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在服务器上。

我无法弄清楚问题是什么。

最佳答案

您好像已经安装了 evenement/evenement:3.0 , 这需要 PHP >=7.0 .我猜您正在使用与运行应用程序不同的 PHP 版本来更新您的依赖项。如果您运行 composer update使用 PHP 7.1,它将安装适用于 PHP 7.1 的依赖项。我建议配置 platform 在您的 composer.json无论本地 PHP 版本如何,都强制安装 PHP 5.5 的依赖项。

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

您也可以禁止 evenement/evenement:3.0composer.json 的约束中您的应用程序 - 如果您希望您的应用程序在 PHP 5 上运行,安装 3.0 行没有多大意义:
"evenement/evenement": "^2.0"

但是使用 platform更可靠 - 这个问题也可能会在其他包中出现,手动管理这个可能会很痛苦。

BTW:你知道 PHP 5.5.9 真的很老了,不再支持 5.5 行了吗?你真的应该至少升级到 PHP 5.6。

关于php - Ratchet 服务器实例化 : "Unsupported declare ' strict_types'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52176996/

相关文章:

php - laravel 4.2 从 phpmyadmin 创建 mysql 数据库而不使用迁移

PHP:有没有办法获取方法的返回类型?

php - 使用 Composer 为项目运行所有 PHPUnit 测试

php - 将 Composer 添加到 Codeigniter 中

发布/订阅中的 Redis 集群与 ZeroMQ,用于水平扩展的分布式系统

PHP 在加载 index.php 时加载 html 文件

php - 两个代码理论上是相同的,但实际上却是不同的……怎么可能

php - 通过 Composer 学说mongodb安装错误

websocket - 为什么操作系统限制文件描述符?

ZeroMQ高水位标记不起作用