property_exists()
property_exists() — Checks if the object or class has a property.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function checks if the given property exists in the specified class.
Signature
property_exists(object|string $object_or_class, string $property): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object_or_class | object|string | The class name or an object of the class to test for |
| $property | string | The name of the property |
Return value
Returns true if the property exists, false if it doesn't exist.
Example
A runnable snippet:
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 var_dump(property_exists('myClass', 'bar')); //false var_dump(property_exists('myClass', 'test')); //true myClass::test();
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page property_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.