array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'de', ), 'this' => array ( 0 => 'function.property-exists.php', 1 => 'property_exists', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => 'Klassen- und Objekt-Funktionen', ), 'prev' => array ( 0 => 'function.method-exists.php', 1 => 'method_exists', ), 'next' => array ( 0 => 'function.trait-exists.php', 1 => 'trait_exists', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'de', 'path' => 'reference/classobj/functions/property-exists.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
property_exists — Prüft, ein Objekt oder eine Klasse auf die angegebene Eigenschaft
Prüft ob die Eigenschaft property
in der angegebenen
Klasse existiert.
Hinweis:
Anders als isset() gibt property_exists() auch dann
true
zurück, wenn eine Eigenschaft den Wertnull
hat.
object_or_class
Der Name der Klasse oder ein Objekt der Klasse, die geprüft werden soll
property
Der Name der Eigenschaft
Beispiel #1 Ein property_exists()-Beispiel
<?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();
?>
Hinweis:
Ein Aufruf dieser Funktion verwendet alle registrierten Autoloader, falls die Klasse nicht bereits bekannt ist.
Hinweis:
Die Funktion property_exists() kann keine Eigenschaften erkennen, die über die 'magische' Methode
__get
implementiert sind.