The property_exists() method checks if the object or class has a property.
Syntax
property_exists(object, property)
Parameters
object/ class − The object or the class name
property − The name of the property
Return
The property_exists() function returns TRUE if the property exists, FALSE if it doesn't exist or NULL in case of an error.
Example
The following is an example −
<?php
class Demo {
public $one;
private $two;
static protected $VAL;
static function VAL() {
var_dump(property_exists('myClass', 'two'));
}
}
var_dump(property_exists('Demo', 'one'));
var_dump(property_exists(new Demo, 'one'));
?>Output
The following is the output −
bool(true) bool(true)