2013-04-03 43 views
2
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 Fatal error: Class 'B' not found in ...

有人能解释为什么出现这种情况?它是一个记录的行为?

PS:PHP 5.3.2

PPS:对ideone相同的行为:http://ideone.com/q4cT6A

回答

1

这是预期在PHP。对不起,答复我也是这样。 ;)从PHP documentation

报价:

Unless autoloading is used, then classes must be defined before they are used. If a class extends another, then the parent class must be declared before the child class structure. This rule applies to classes that inherit other classes and interfaces.

+0

一切* *预期应以某种方式记录;-) – zerkms

+0

做........... :) – hek2mgl

+0

“如果一个类继承另一个,那么父类必须在子类结构之前声明“---并且这种行为*更奇怪*:http://ideone.com/ZDx0O7 – zerkms

相关问题