PHP method_exists() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The method_exists() function is an inbuilt function in PHP which used to check the class method exists or not. It returns "true" if the method exists otherwise returns "false". Syntax: bool method_exists( object|string $object_or_class, string $method );Parameters: This function accepts two parameters that are described below: $object_or_class: It contains the name of the object or class.method: It contains the name of the method.Return Value: This method returns "true" if the class method exists in a given object or class, and false otherwise. Example 1: In this example, we will check method_exists() in a given class or object, if not exists it will return "true". PHP <?php $directory = new Directory('.') ; var_dump(method_exists($directory,'read')); ?> Output: bool(true);Example 2:Â In this example, we will check for "redirect" in method_exists() in a given class or object, if not it will return "false". PHP <?php $directory = new Directory('.') ; var_dump(method_exists($directory,'redirect')); ?> Output: bool(false); Reference: https://www.php.net/manual/en/function.method-exists.php Comment More infoAdvertise with us Next Article PHP method_exists() Function neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Classes/Object-Functions Similar Reads PHP key_âexists() Function The key_exists() function is an inbuilt function in PHP that is used to check whether the given key exist in the given array or not. If given key exist in the array then it returns true otherwise returns false. This function is an alias of array_key_exists() function. Syntax: bool key_exists(string| 2 min read PHP | function_exists() Function The function_exists() is an inbuilt function in PHP. The function_exists() function is useful in case if we want to check whether a function() exists or not in the PHP script. It is used to check for both built-in functions as well as user-defined functions. Syntax: boolean function_exists($function 2 min read PHP | exit( ) Function The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The message 2 min read PHP file_exists( ) Function The file_exists() function in PHP checks whether a file or directory exists on the server. It returns a boolean value:true: If the file or directory exists.false: If the file or directory does not exist or the path is incorrect.Syntax:file_exists($path)In this syntax: The file_exists() function in P 2 min read PHP array_key_exists() Function The array_key_exists() function in PHP is a built-in function that checks whether a specified key exists in an array. This function is commonly used when working with associative arrays, where keys are explicitly defined, and we need to confirm the presence of a particular key to prevent errors or u 2 min read PHP interface_exists() Function The interface_exists() function is an inbuilt function in PHP that checks interface is defined or not. Syntax: bool interface_exists(string $interface, bool $autoload = true)Parameters: This function accept two parameters that are described below: $interface: This parameter holds the interface name. 1 min read PHP enum_exists() Function The enum_exists() is an inbuilt function in PHP that checks whether the enum is defined or not in the PHP script. Syntax: enum_exists(string $enum, bool $autoload = true) Parameters: This function has two parameters. $enum: The enum name.The name is match in an insensitive manner.$autoload: This par 1 min read PHP | class_exists() Function The class_exists() function is an inbuilt function in PHP which is used to check whether the given class is defined or not. Syntax: bool class_exists( string $class_name, bool $autoload = TRUE ) Parameters: This function accept two parameters as mentioned above and described below: $class_name: It h 2 min read PHP | get_class() Function The get_class() function is an inbuilt function in PHP which is used to return the class name of an object. Syntax: string get_class( object $object ) Parameters: This function accepts single parameter $object which holds the object that need to be tested. The value of this parameter can be omitted 1 min read PHP property_exists() Function The property_exists() function is an inbuilt function in PHP that is used to check objects and classes have properties or not. Syntax: bool property_exists(object|string $object_or_class, string $property);Parameters: This function accept two parameters that are described below: $object_or_class: Th 2 min read Like