PHP Determines if {function/class/method/property} exists

Source: Internet
Author: User

1.php determine whether a system function or a function written by itself exists

BOOL Function_exists (string $function _name) determines whether a function has been defined, for example:

if (function_exists(' Curl_init ')) {    curl_init ();} Else {    echo ' not function Curl_init ';}

2.php determining whether a class exists

BOOL Class_exists (String $class _name [, bool $autoload = true]) checks whether a class has been defined, must return True, otherwise returns false, for example:

if (class_exists(' MySQL ')) {    $myclass=newMySQL();}

3.php determines whether a method within a class has been defined

BOOL Method_exists (mixed $object, string $method _name) checks for the existence of a method of a class, for example:

$directory=new  directory; if (! method_exists ($directory, ' read ') {    echo ' does not define the Read Method!} ';}

4.php determines whether a property within a class has been defined

BOOL property_exists ( mixed $class , string $property ) checks for the existence of a class's properties, for example:

$directory=new  directory; if (!property_exists ($directory, ' Li ')) {    echo ' does not have an LI attribute defined! ';}

PHP Determines if {function/class/method/property} exists

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.