Home > Backend Development > PHP Tutorial > PHP中类的嵌套及继承解决方案

PHP中类的嵌套及继承解决方案

WBOY
Release: 2016-06-13 10:03:28
Original
1116 people have browsed it

PHP中类的嵌套及继承
在A类中嵌套个B类,且B类是继承的C类,可以实现吗?

------解决方案--------------------
类是肯定不能嵌套的啦.
------解决方案--------------------
他说嵌套应该是说实例化进来一个类吧。。。。。。。。=_=
------解决方案--------------------
嵌套是什么意思?实例化的话当然可以,类中定义类应该不可以吧。
------解决方案--------------------
没这样的写法.你为什么要这么写? 


你是不是要实现这样?


PHP code
class C{    public $C = 'Cname';}class B extends  C{    public $B = 'Bname';}class A{        public $B;    function load()    {        $this -> B  = new B();    }}$A = new A();$A -> load();echo $A -> B -> C;echo $A -> B -> B;<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template