PHP method_exists () function usage

Source: Internet
Author: User

Method_exists

(PHP 4, PHP 5, PHP 7)

method_exists-Check if the method of the class exists

Description

BOOL Method_exists (mixed $object, string $method _name)

Returns TRUE if the method referred to in method_name is defined in the object class referred to by object, otherwise returns FALSE.

The code is as follows Copy Code

Class A {
Public Function xx () {
echo ' xx ';
}

Public Function yy () {
Echo ' yy ';
}
}

$obj = new A ();

Var_dump (method_exists ($obj, ' xx '));
Var_dump (method_exists ($obj, ' xx '));
Var_dump (method_exists ($obj, ' xx '));

The test results are true

Class A {
Public Function xx () {
echo ' xx ';
}

Public Function yy () {
Echo ' yy ';
}

Public Function yy () {
Echo ' yy ';
}
}

$obj = new A ();
$obj->yy ();
$obj->yy ();

The above statement is an error.

Example

  code is as follows copy code

//Get action to run
include ($c _path);

//Load Controller file
$controller = new $c _name ($query);

If (isset ($_get[' m ')) {
  $method = $_get[' m '];
 
 if ($controller, $method ) {
$controller-> $method ();
 }
} else {
 //performs the first function
  $controller->index ();
}

Related Article

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.