How PHP is going to search for a class

Source: Internet
Author: User
Search for PHP-class Linux path

I don't want to ask special classes, just the basics, what is the basic principle of the PHP search class, For example, I quoted a Test2 class in test1.php, the declaration of this class in test2.php, then how will PHP find this class, I put test2.php in the current directory, but also hint that the error did not find the class AH. Get_include_path () also has this path. Need to go to config file to do something? I am under the Linux, did not find the online php.ini brother just contact PHP, which elder brother can explain here?


Reply to discussion (solution)

Include (' test2.php ');
...
?>

If you do not explicitly tell PHP where to look, then PHP will not do invalid labor (because the search through the entire hard disk may not be found)
1, you can explicitly include, Require loading class definition files
2. You can define a __autoload function that will be called automatically when you try to use a class that is not already defined. By calling this function, the scripting engine has the last chance to load the required classes before PHP fails.
3. You can also use the SPL_XXX function group to load your class

  • 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.