How does php search for a class?

Source: Internet
Author: User
How does php search for a class I don't want to ask some special classes, but the most basic situation is what is the basic principle of the php search class, for example, I referenced a Test2 class in test1.php. the declaration of this class is in test2.php. how does php find this class? I put test2.php under the current directory, however, the error message "how to search for a class in php" is not found.
I don't want to ask some special classes, but the most basic situation is what is the basic principle of the php search class. for example, I referenced a Test2 class in test1.php, the declaration of this class is in test2.php, so how does php find this class? I put test2.php under the current directory, but I also indicated that the class was not found due to an error. This path is also available in get_include_path. What do I need to do in the configuration file? In linux, I did not find the online php. ini younger brother who just came into contact with php. which eldest brother can explain this? Search for php-like linux path and share it:
------ Solution --------------------
If you do not explicitly tell php where to find it, php will not do ineffective work (because the entire hard disk may not be found)
1. you can explicitly include and require the class definition file.
2. you can define a _ autoload function, which is automatically called when trying to use a class that has not been defined. By calling this function, the script engine has the last chance to load the required class before a PHP error 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.