PHP 7,Symfony 3:致命错误1抽象方法,因此必须声明抽象或实现其余方法


PHP 7, Symfony 3: Fatal error 1 abstract method and must therefore be declared abstract or implement the remaining methods

在从5.6更新到7的php更新之后,Symfony 3会引发以下异常:

致命错误:类 Symfony''Component''HttpFoundation''Session''Storage''Proxy''SessionHandlerProxy 包含 1 个抽象方法,因此必须声明为抽象或 实现其余方法(SessionHandlerInterface::write) ''vendor''symfony''symfony''src''Symfony''Component''HttpFoundation''Session''Storage''Proxy''SessionHandlerProxy.php 在第 19 行

Symfony 3 与 PHP 7 不兼容吗? 相同的代码适用于PHP 5.6

作曲家显示 -i 输出:

doctrine/annotations                 v1.2.7  Docblock Annotations Parser
doctrine/cache                       v1.6.0  Caching library offering an o...
doctrine/collections                 v1.3.0  Collections Abstraction library
doctrine/common                      v2.6.1  Common Library for Doctrine p...
doctrine/dbal                        v2.5.3  Database Abstraction Layer
doctrine/doctrine-bundle             1.6.1   Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.2.2   Symfony Bundle for Doctrine C...
doctrine/inflector                   v1.1.0  Common String Manipulations w...
doctrine/instantiator                1.0.5   A small, lightweight utility ...
doctrine/lexer                       v1.0.1  Base library for a lexer that...
doctrine/orm                         v2.5.3  Object-Relational-Mapper for PHP
incenteev/composer-parameter-handler v2.1.2  Composer script handling your...
jdorn/sql-formatter                  v1.2.17 a PHP SQL highlighting library
kriswallsmith/assetic                v1.3.2  Asset Management for PHP
monolog/monolog                      1.17.2  Sends your logs to files, soc...
paragonie/random_compat              v1.2.2  PHP 5.x polyfill for random_b...
psr/log                              1.0.0   Common interface for logging ...
sensio/distribution-bundle           v5.0.3  Base bundle for Symfony Distr...
sensio/framework-extra-bundle        v3.0.12 This bundle provides a way to...
sensio/generator-bundle              v3.0.3  This bundle generates code fo...
sensiolabs/security-checker          v3.0.2  A security checker for your c...
swiftmailer/swiftmailer              v5.4.1  Swiftmailer, free feature-ric...
symfony/assetic-bundle               v2.7.1  Integrates Assetic into Symfony2
symfony/monolog-bundle               v2.8.2  Symfony MonologBundle
symfony/phpunit-bridge               v2.8.1  Symfony PHPUnit Bridge
symfony/polyfill-intl-icu            v1.1.1  Symfony polyfill for intl's I...
symfony/polyfill-mbstring            v1.1.1  Symfony polyfill for the Mbst...
symfony/polyfill-php56               v1.1.1  Symfony polyfill backporting ...
symfony/polyfill-php70               v1.1.1  Symfony polyfill backporting ...
symfony/polyfill-util                v1.1.1  Symfony utilities for portabi...
symfony/swiftmailer-bundle           v2.3.9  Symfony SwiftmailerBundle
symfony/symfony                      v3.0.3  The Symfony PHP framework
twig/twig                            v1.24.0 Twig, the flexible, fast, and...

PHP.ini

[opcache]
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=6000
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.save_comments=1
opcache.fast_shutdown=1

重新启动 httpd 服务可以清除此错误。

遇到错误后无法重现错误,但可能是 PHP 崩溃,进而导致不完整状态,使错误消息卡在 httpd 服务的缓冲区响应中,然后为该服务上提供的任何 vhost 的每个请求提供服务,直到服务被终止。

信贷斯科特·弗拉克在另一个答案中评论道。

尝试升级到Symfony 3.1。

Symfony 3.0于2015年11月发布,虽然它应该与PHP7兼容,但PHP7直到2015年12月正式发布。