PHP property_exists() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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: The name of the class or object to test for the property.$property_name: This name of the property in the class.Return Value: This function returns true if the property exists, and false if property doesn't exist, and null in case of getting an error. Example 1: In this example, we will check whether the property is in class or not by using the PHP property_exists() function in PHP. PHP <?php class My_Class_Property_Check { public $name; private $empid; protected $salary; static function check_prop() { var_dump(property_exists( 'My_Class_Property_Check', 'empid')); } } // If the property exists it will be // return true otherwise false var_dump(property_exists( 'My_Class_Property_Check', 'name')); var_dump(property_exists( 'MY_Class_Property_Check', 'salary')); My_Class_Property_Check::check_prop(); ?> Output: bool(true) bool(true) bool(true)Example 2: In this example, we will check the property using the object of the class using PHP property_exists() method. PHP <?php class My_Class_Property_Check { public $name; private $empid; protected $salary; static function check_prop() { var_dump(property_exists( new My_Class_Property_Check, 'empid')); } } // If the property exists it will be // return true otherwise false var_dump(property_exists( new MY_Class_Property_Check, 'salary')); // This property does not exists // so it will return false var_dump(property_exists( new MY_Class_Property_Check, 'net_salary')); My_Class_Property_Check::check_prop(); ?> Output: bool(true) bool(false) bool(true) Reference: https://www.php.net/manual/en/function.property-exists.php Comment More infoAdvertise with us Next Article PHP property_exists() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Classes/Object-Functions Similar Reads 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 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 method_exists() Function 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 paramete 1 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 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 Like