PHP类继承深度 [英] PHP class inheritance depth

查看:152
本文介绍了PHP类继承深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,如果我从A类开始



类扩展A类

Class C扩展类B

D类扩展类C

Class E扩展D类

类F扩展E类

类G扩展F类



大部分较低级别是抽象类,方法填充代码和抽象方法。它是一个相当大而复杂的结构。 (做我的头)



G类仍然可以访问A类方法和参数,以及仍然可以访问A类的抽象方法? / p>

我问,因为我已经遇到了eclipse的麻烦,没有将较低级的方法添加到自动完成。我想知道实际上是否有限制,或者是否只是日食达到代码完成的最大值。



我远离我可以测试这个与我已经做了什么,不想找到什么时候我完成那些方法定义较低的顺序是不可访问的。

解决方案

听起来像编辑器的问题。例如,请参阅以下快速和肮脏的演示:

  php> class a {function foo(){echoA :: foo()\\\
; }}
php> $ letters = range('a','z');
php> for($ i = 0; $ i< 25; $ i ++){eval(class {$ letters [$ i + 1]} extends {$ letters [$ i]} {}); }
php> $ z = new z;
php> $ Z-> FOO();
A :: foo()

PHP不会施加任何类似的限制在你身上。


I'm trying to work out exactly how deep inheritance goes.

For example if I start with class A

Class B extends class A
Class C extends class B
Class D extends class C
Class E extends class D
Class F extends class E
Class G extends class F

most of the lower levels are abstract classes with methods filled with code and abstract methods. its a rather large and complex structure. (doing my head in)

Will Class G still be able to access Class A methods and parameters, as well as still have access to the abstract methods from Class A ?

I'm asking because I have been having trouble with eclipse not adding the lower class methods into the auto complete. I would like to know if there is actually a limit to this or whether it's just eclipse reaching its maximum for code completion.

I'm far from a stage where I can test this with what I have done and don't want to find when I'm done that methods defined lower in the order are not accessible.

解决方案

Sounds like a problem with your editor. For example, see the following quick-and-dirty demonstration:

php > class a { function foo() { echo "A::foo()\n"; } }
php > $letters = range('a', 'z');
php > for ($i = 0; $i < 25; $i++) { eval("class {$letters[$i+1]} extends {$letters[$i]} {}"); }
php > $z = new z;
php > $z->foo();
A::foo()

PHP doesn't impose any kind of restriction like this on you.

这篇关于PHP类继承深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆