test1()); class teststring extends father{ public function test1(){ return 1; } }
为什么会报错?
fatal error: class 'teststring' not found
如果我去掉extends father之后就可以正常输出了。
回复内容: test1()); class teststring extends father{ public function test1(){ return 1; } }
为什么会报错?
fatal error: class 'teststring' not found
如果我去掉extends father之后就可以正常输出了。
第一,从你贴出来的代码看,你应该是写在两个文件之中,在 teststring 类文件中没有 require 或 include father类文件。
第二,也是你这个问题的关键所在,类声明的顺序,在文件编译过程中,编译到 teststring 类声明时,发现没有father类(即未声明),这时 teststring 类声明失败, 这个你可以用class_exists()来验证一下。所以在实例化 teststring类的时候报错 class 'teststring' not found。
将父类在继承其的子类之前声明就可以了。
因为你的定义在调用的后面呀
肯定错啊。
顺序执行,teststring还没定义,你就new了。
请将父类写到子类前面,请在定义类以后在实例化