property_exists — 객체나 클래스가 프로퍼티를 가졌는지 확인 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

property_exists — 객체나 클래스가 프로퍼티를 가졌는지 확인 정보

PHP property_exists — 객체나 클래스가 프로퍼티를 가졌는지 확인

본문

property_exists — 객체나 클래스가 프로퍼티를 가졌는지 확인

 

설명 :

bool property_exists ( mixed $class , string $property )

주어진 property가 지정한 클래스에 존재하는지 확인합니다.

 

Note:

isset()과 다르게, property_exists()는 프로퍼티가 NULL 값을 가지고 있어도 TRUE를 반환합니다.

 

인수 :

class

확인할 클래스명이나 클래스의 객체

 

property

프로퍼티명

 

반환값 :

프로퍼티가 존재하면 TRUE, 존재하지 않으면 FALSE, 오류시엔 NULL을 반환합니다.

 

예제 :

 

Example #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, as of PHP 5.3.0

var_dump(property_exists('myClass', 'bar'));    //false

var_dump(property_exists('myClass', 'test'));   //true, as of PHP 5.3.0

myClass::test();

 

?>

추천
0

댓글 0개

전체 5,352
개발자팁 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT