English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Class/Object function reference manual
The property_exists() function checks whether an object or class has the specified property
property_exists ($object, $property);
This function checks whether the given property exists in the specified class (and whether it can be accessed from the current scope).
Number | Parameters and descriptions |
---|---|
1 | object (required) A string representation of a class name or an object of the class to be checked |
2 | property (required) The name of the property. |
If the property exists, it returns TRUE; if the property does not exist, it returns FALSE; if an error occurs, it returns NULL.
The following is the usage of this function-
<?php class myClass { public $mine; private $xpto; static protected $test; static function test() { var_dump(property_exists('myClass', 'xpto')); //true } } var_dump(property_exists('myClass', 'mine')); //true var_dump(property_exists(new myClass, 'mine')); //true var_dump(property_exists('myClass', 'xpto')); //true, from PHP 5.3From version .0 var_dump(property_exists('myClass', 'bar')); //false var_dump(property_exists('myClass', 'test')); //true, from PHP 5.3From version .0 myClass::test(); ?>