PHP inheritance prompt cannot find parent class

Source: Internet
Author: User
Run the Code directly. {Code...} Why? The two files are in the same folder and directory. It should be fine if they are not included, and the inheritance commonly used in the framework is not include. Run the Code directly.

namespace 'Test';class A{    }
Namespace 'test'; // if you run B directly, an error is returned, indicating that AAinclude 'a. php' cannot be found. // after adding include, class B extends A {} can be created {}

Why? The two files are in the same folder and directory. It should be fine if they are not included, and the inheritance commonly used in the framework is not include.

Reply content:

Run the Code directly.

namespace 'Test';class A{    }
Namespace 'test'; // if you run B directly, an error is returned, indicating that AAinclude 'a. php' cannot be found. // after adding include, class B extends A {} can be created {}

Why? The two files are in the same folder and directory. It should be fine if they are not included, and the inheritance commonly used in the framework is not include.

That's because the framework has already registered its ownautoloadSo when you needAIf the current file does not containAThis class triggersautoloadMechanism, throughautoloadSetAFile corresponding to the classincludeCome in.

I want to learn more about the basics, but how can I use it without include? The framework must also be included, but it is encapsulated.

If you do not use include, you will call autoload to search for Class A in the default file location. Obviously, the current folder is not in the default location?

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.