【问题标题】:PHP7 Type error with interfacePHP7类型错误与界面
【发布时间】:2017-12-31 12:52:38
【问题描述】:

在我的 symfony 项目中,我遇到了供应商的错误。

致命错误:未捕获 Symfony\Component\Debug\Exception\FatalThrowableError:类型错误:参数 1 传递给 eZ\Publish\Core\MVC\Legacy\Kernel\Loader::setCLIHandler() 必须实现接口 ezpKernelHandler,eZ 的实例\Publish\Core\MVC\Legacy\Kernel\CLIHandler 给定,在 /Users 的第 237 行调用 /Users/steve/Projects/Web/BuildSuccess/www/vendor/ezsystems/legacy-bridge/mvc/Kernel/Loader.php /steve/Projects/Web/BuildSuccess/www/vendor/ezsystems/legacy-bridge/mvc/Kernel/Loader.php:255

但是这个错误很奇怪,因为我检查了 eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler 实现了接口 ezpKernelHandler !

namespace eZ\Publish\Core\MVC\Legacy\Kernel;

use ezpKernelHandler;

class CLIHandler implements ezpKernelHandler
{
   ...
}

我尝试调试,使用 get_class 方法,我得到了

"eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler"

我也使用了 class_implements 方法,我得到了

array(0) {
}

知道附加什么吗?

谢谢

【问题讨论】:

  • 由于 ezpKernelHandler 没有命名空间 - 它可能应该被引用为 \ezpKernelHandler
  • 我尝试添加\但得到同样的错误
  • 接口 ezpKernelHandler 是否与 CLIHandler 在同一命名空间中?

标签: php symfony


【解决方案1】:

我发现这不是您的代码,而是eZ Publish 本身。因此,您不太可能更新源,但您仍然可以做一些事情:

  1. 检查您的 Composer 自动加载器配置,查看 ezpKernelHandler 类是否已正确解析。您可能需要为其注册自定义自动加载器。

  2. 您很可能收到此错误,因为您使用的是 Symfony 3.3+ 及其最近添加的 services auto-configuration 功能。您可以通过禁用受影响服务的服务自动配置来避免引发此错误,请查看示例here

  3. 由于此错误是致命的,但可以捕获 - 如果没有其他帮助,您可以为该特定服务创建自己的服务工厂并在其中捕获错误。

【讨论】:

  • 我试图禁用自动装配和自动配置,但我得到了同样的错误。你能解释一下如何做1。?在哪里检查作曲家自动加载器配置?我应该看到什么?以及如何为 ezpKernelHandler 注册自定义自动加载器?谢谢
  • 您可以使用composer dump-autoload -o 创建优化的类加载器,然后您可以检查vendor/composer/autoload_classmap.php - 它将包含所有已知类的列表以及它们的路径。检查路径是否正确。使用spl_autoload_register函数可以创建和注册自定义自动加载器。
【解决方案2】:

已修复:https://github.com/ezsystems/LegacyBridge/issues/132

通过创建需要 vendor/autoload.php 和 ezpublish_legacy/autoload.php 的 app/autoload.php 文件并将 bin/console 更改为需要该文件而不是 vendor/autoload.php 可以轻松解决此问题

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2021-12-24
    • 2020-11-20
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    相关资源
    最近更新 更多