• PHP Video Tutorials

PHP - Function method_exists()



Syntax

method_exists ( $object, $method_name );

Definition and Usage

It checks if the class method exists in the given object.

Parameters

Sr.No Parameter & Description
1

object(Required)

The tested object

2

mthod_name(Required)

The method name.

Return Value

It returns TRUE if the method given by method_name has been defined for the given object, FALSE otherwise.

Example

Following is the usage of this function −

<?php
   $directory = new Directory('.');
   var_dump(method_exists($directory,'anything'));
?> 

It will produce the following result −

bool(false)
php_function_reference.htm
Advertisements