new A;
class A {}
new C;
class C extends A {}
new B;
class B implements iB {}
interface iB {} // we can even put interface definition after the class
// that implements it
我希望这段代码可以正常工作,而我正在
PHP致命错误:在......中找不到“B”类
有人可以解释为什么会这样吗?这是记录在案的行为吗?
PS:php 5.3.2
PPS:在ideone上的行为相同:http://ideone.com/q4cT6A
答案 0 :(得分:1)
这是在PHP中的预期。对不起答案,我也曾预料到这一点。 ;)
的引用除非使用自动加载,否则必须在使用之前定义类。如果类扩展另一个类,则必须在子类结构之前声明父类。此规则适用于继承其他类和接口的类。