클래스/객체 property_exists

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

property_exists — 객체 또는 클래스에 속성이 있는지 확인


설명

property_exists(object|string $object_or_class, string $property): bool

이 함수는 지정된 property이 지정된 클래스에 존재하는지 확인합니다.

메모: isset()과 달리 property_exists()는 속성 값이 null인 경우에도 true를 반환합니다.


매개변수

object_or_class
테스트할 클래스의 이름 또는 객체
property
property의 이름

반환 값

property이 있으면 true를 반환하고, 없으면 false를 반환하고, 오류가 발생하면 null을 반환합니다.


Examples

예제 #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();

?>
                  
                

메모

메모: 클래스가 아직 알려지지 않은 경우 이 함수를 사용하면 등록된 autoloaders가 사용됩니다.

메모: property_exists() 함수는 __get 매직 메서드를 사용하여 마법처럼 액세스할 수 있는 속성을 감지할 수 없습니다.


기타