【问题标题】:symfony 3 app fails silently to require_once in DebugClassLoadersymfony 3 应用程序在 DebugClassLoader 中静默地要求 require_once 失败
【发布时间】:2016-07-11 13:47:48
【问题描述】:

我有一个名为 FilterInput 的 PHP 类。当我基于 Symfony (3.0.3) 的应用程序调用 FilterInput 的静态成员函数时,会隐式调用 Symfony 的 DebugClassLoader。该方法称为loadClass,它的开头是这样的:

public function loadClass($class)
{
    ErrorHandler::stackErrors();

    try {
        if ($this->isFinder) {
            if ($file = $this->classLoader[0]->findFile($class)) {
                require_once $file;
            }
        } else {
            call_user_func($this->classLoader, $class);
            $file = false;
        }
    } finally {
        ErrorHandler::unstackErrors();
    }
...

我观察到的问题是,当执行到达include_once 指令时,应用程序会静默失败。也就是说,http 请求返回空,dev.log 或我的 apache 日志中没有输出。我已验证$file 变量包含完整且正确的/path/to/FilterInput.php。我还验证了这个文件是可读的。所以我的问题是:

  1. 为什么此时会停止执行?
  2. 为什么它会静默失败,没有日志错误消息或在响应中返回数据。

编辑:更多信息:如果我填写垃圾路径,例如"/foo/bar" 然后我收到一条错误消息Compile Error: AppBundle\Components\Factory::getDBO(): Failed opening required '/foo/bar' (include_path='.:');所以推测无声失败与在给定路径下一个文件的事实有关。

【问题讨论】:

  • 您确定处于开发模式吗?在您的 app.php 中,确保您像这样实例化您的 AppKernel:$kernel = new AppKernel('dev', true);
  • 这帮助我找到了很多以前被忽略的错误 - 但我仍然在 require_once 时遇到 silent 失败

标签: php symfony


【解决方案1】:

require_once 会在以下指令中静默失败:

defined('PATH_BASE') or die();

出现在源文件的头部;并且所需的定义不存在

【讨论】:

    猜你喜欢
    • 2017-04-27
    • 2015-06-01
    • 2017-08-31
    • 1970-01-01
    • 2011-12-04
    • 2020-05-19
    • 2013-11-04
    • 1970-01-01
    • 2014-06-12
    相关资源
    最近更新 更多