Analysis on the usage of php to determine whether a class has a function class_exists

Source: Internet
Author: User
Tags autoload
This article mainly introduces the usage of the class_exists function in php to determine whether a class exists, and analyzes the application of PHP to determine whether a class exists, it is very useful for judging the existence of classes automatically loaded and classes before class instantiation.

This article mainly introduces the usage of the class_exists function in php to determine whether a class exists, and analyzes the application of PHP to determine whether a class exists, it is very useful for judging the existence of classes automatically loaded and classes before class instantiation.

This article analyzes the usage of the php function class_exists to determine whether a class exists. Share it with you for your reference. The details are as follows:

If we want to determine whether a class can be used, we can use the class_exists function to determine whether a class can be used. Here are several examples.

Bool class_exists (string $ class_name [, bool $ autoload = true])
Whether the class specified by this function is defined and checked. This function checks whether or not the given class has been defined.
Returns true. If class_name is a defined class, otherwise, false is returned.

Example:

The Code is as follows:

Function _ autoload ($ class)
{
Include ($ class. '. php ');
// Check to see whether the include declared the class
If (! Class_exists ($ class, false )){
Trigger_error ("unable to load class: $ class", e_user_warning );
}
}
If (class_exists ('myclass ')){
$ Myclass = new myclass ();
}

I hope this article will help you with PHP programming.

,

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.