array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ru', ), 'this' => array ( 0 => 'function.property-exists.php', 1 => 'property_exists', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => 'Функции работы с классами и объектами', ), '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' => 'ru', '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 — Проверяет, есть ли у объекта или класса свойство
Функция проверяет, существует ли свойство property
в указанном классе.
Замечание:
В противоположность языковой конструкции isset(), функция property_exists() возвращает
true
, даже если значение свойства равноnull
.
object_or_class
Имя класса или объект класса для проверки.
property
Имя свойства.
Пример #1 Пример использования функции property_exists()
<?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();
?>
Замечание:
Вызов этой функции будет использовать все зарегистрированные функции автозагрузки, если класс ещё не известен.
Замечание:
Функция property_exists() не определяет свойства, которые магически доступны через магический метод
__get
.