【问题标题】:PHP does not report parse errors if error is caused within declared namespace如果在声明的命名空间内导致错误,PHP 不会报告解析错误
【发布时间】:2013-07-07 23:19:44
【问题描述】:

StackOverflowers 的同胞!

我遇到了奇怪的问题。让我写一个简短的描述:

这是我的文件夹层次结构

  • \sys\core\core.php 声明命名空间 sys\core 和类名 core
  • \sys\traits\singleton.php 声明命名空间 sys\traits 和 trait 名称 singleton
  • \pub\index.php(没有声明的命名空间,包括自动加载功能,它负责休息 - 根据命名空间声明加载文件)

\sys\traits\singleton.php

trait singleton {

    private static $_instance = false;

    public static function get_instance() {

        if( self::$_instance == false ) {

            self::$_instance = new self();
        }

        return self::$_instance;
    }

}

\sys\core\core.php

namespace sys\core;

class core {
    use \sys\traits\singleton;

    public function __construct() {
        $ =; // just an example, it shall produce a nice parse error but it wont :(
    }
}

\pub\index.php 我有

error_reporting(E_ALL);

// some constants defined

require('path/to/my/autoload/which/works/correctly.php');

use sys\core\core as core;

$core = core::get_instance();

$core->load_controller();

基本上,任何类型的错误 (parse error / warning etc) 都会显示,除非是在命名空间内引起的。因此,\pub\index.php 中的任何错误都会被正确报告(根据需要),但是在声明命名空间的文件中出现的每个错误都会导致白页,没有显示错误(尽管 error_reporting 在任何可能的地方都设置为E_ALL - 甚至在 php.ini 中)

我的配置信息:

通过 PHP-FPM 运行的 PHP 5.5.0(来自 dotdeb.org 的软件包) nginx 1.4.1(来自dotdeb.org的包,nginx的error.log也是空的,即使它正常保存任何类型的PHP错误) 在 Debian 上运行(测试/Sid)

任何提示/提示我错过了什么?我会感谢任何信息!提前致谢!

【问题讨论】:

    标签: php namespaces traits


    【解决方案1】:

    问题已解决(尽管它没有连接到命名空间)

    @ before include() 不会消除包含的错误,它会消除包含文件中抛出的所有错误(我想知道从什么时候开始是这样的......)

    无论如何,问题可以被关闭、利用和遗忘

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 2018-07-24
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      相关资源
      最近更新 更多