所以,如果你尝试做一个这样的嵌套类:
//nestedtest.php
class nestedTest{
function test(){
class E extends Exception{}
throw new E;
}
}
你会得到一个错误Fatal error: Class declarations may not be nested in [...]
但是如果你在一个单独的文件中有一个类,像这样:
//nestedtest2.php
class nestedTest2{
function test(){
include('e.php');
throw new E;
}
}
//e.php
class E Extends Exception{}
那么,为什么第二种 hacky 的做法有效,但 non-hacky 的做法却行不通呢?