property_exists
property_exists
Checks if the object or class has a property
bool **property_exists** $object_or_class string $property
This function checks if the given exists in
the specified class.
property
Opmerking: > As opposed with , returns true even if the property has the value null.
isset``property_exists
object_or_classThe class name or an object of the class to test for
propertyThe name of the property
Returns true if the property exists, false if it doesn't exist.
Voorbeeld: A example
<?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
var_dump(property_exists('myClass', 'bar')); //false
var_dump(property_exists('myClass', 'test')); //true
myClass::test();
?>
Opmerking: > The function cannot detect properties that are magically accessible using the magic method.
property_exists__get
method_exists