PHP inheritance hint could not find parent class

Source: Internet
Author: User
Tags autoload
Go directly to the code.

namespace 'Test';class A{    }
namespace 'Test';//直接运行B会报错,提示找不到AAinclude 'A.php';//加上include这句后,就可以了class B extends A{    }

What is this for? Two files in the same folder, also in the same directory, not include should also be no problem, the framework of common inheritance also does not include.

Reply content:

Go directly to the code.

namespace 'Test';class A{    }
namespace 'Test';//直接运行B会报错,提示找不到AAinclude 'A.php';//加上include这句后,就可以了class B extends A{    }

What is this for? Two files in the same folder, also in the same directory, not include should also be no problem, the framework of common inheritance also does not include.

That's because the framework has already registered itself in front of it autoload , so when you need it A if the current file doesn't have A this class, then it triggers the autoload mechanism by passing in the autoload file that corresponds to A the class include .

Learn to learn the basis of it, not include how can be used, the framework must also be for the include, but for the package is good

Call AutoLoad to the default file location without the include to find a class, it is clear that 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.