以下内容适用于PHP 5.3,但不适用于PHP 5.4.10.
throw new Custom_Exception();
class Custom_Exception extends Exception {}
Run Code Online (Sandbox Code Playgroud)
PHP 5.4.10会响应以下致命错误:
在'...中找不到类'Custom_Exception'
有谁知道为什么?
ps在throw语句上面移动类定义会修复它.
我将您的代码放入名为 test.php 的文件中,并下载了php-5.4.10
当我执行时:
php -c php.ini-development -f test.php
Run Code Online (Sandbox Code Playgroud)
我看到以下输出:
PHP Fatal error: Uncaught exception 'Custom_Exception' in test.php:3
Stack trace:
#0 {main}
thrown in test.php on line 3
Fatal error: Uncaught exception 'Custom_Exception' in test.php:3
Stack trace:
#0 {main}
thrown in test.php on line 3
Run Code Online (Sandbox Code Playgroud)
我相信您有配置问题。您是从命令行进行测试吗?
编辑:
我还比较了两个版本的 zend_compile.c 中的 do_bind_inherited_class 。
看起来他们只是增加了对特征的支持。
我的回答是:不,我不相信态度已经改变。