PHP class nesting and inheritance solution

Source: Internet
Author: User
In PHP, the class is nested and inherited. Class A is nested with Class B, and class B is inherited with class C. can it be implemented ?, Class is certainly not nested. he Said That nesting should mean instantiating a class ........ ===, What does nesting mean? Of course, it can be instantiated. it is not possible to define a class in a class ., No. why are you writing this? & Nbsp; do you want to implement this? Class nesting and inheritance in PHPcod PHP
A class B is nested in Class A, and class B is an inherited class C. can it be implemented?

------ Solution --------------------
Classes cannot be nested.
------ Solution --------------------
He said that nesting should mean instantiating a class ........ ===
------ Solution --------------------
What does nesting mean? Of course, it can be instantiated. it is not possible to define classes in a class.
------ Solution --------------------
No. why are you writing this?


Do you want to achieve this?


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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.