method_exists

Checks if the class method exists

Syntax

method_exists ( mixed $object , string $method_name ) : bool

Parameters

object

An object instance or a class name

method_name

The method name

Return

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

Examples

1

<?

class myclass
{
    function myfunction()
    {
    }
}

$object = new myclass();
$method_name = "myfunction";

$return = method_exists($object, $method_name);

var_export($return);

?>
true

2

<?

class myclass
{
    function myfunction()
    {
    }
}

$object = "myclass";
$method_name = "myfunction";

$return = method_exists($object, $method_name);

var_export($return);

?>
true

class_alias

class_exists

get_called_class

get_class

get_class_methods

get_class_vars

get_declared_classes

get_declared_interfaces

get_declared_traits

get_object_vars

get_parent_class

interface_exists

is_a

is_subclass_of

property_exists

trait_exists

PHP

Home Menu