Does a property exists in an object ?

Submitted by Jérémy on

How to check if a property exist in an object :

property_exists

if (property_exists($object, 'property')) {
    return TRUE;
}

isset

if (isset($object->property)) {
    return TRUE;
}

Results

Warning, if the value of the property is NULL, isset will return FALSE !

Function property_exists isset
Average in seconds for 1000000 calls 0.1664 0.1043