Reflection ReflectionClass::getProperties
(PHP 5, PHP 7, PHP 8)
ReflectionClass::getProperties — 속성 가져오기
설명
public ReflectionClass::getProperties(?int $filter
= null
): array
반사된 속성을 검색합니다.
매개변수
filter
- 원하는 속성 유형을 필터링하기 위한 선택적 필터. ReflectionProperty 상수를 사용하여 구성되며 기본값은 모든 속성 유형입니다.
반환 값
ReflectionProperty 개체의 배열입니다.
변경 로그
버전 | 설명 |
---|---|
7.2.0 | filter 는 이제 nullable입니다. |
Examples
예제 #1 ReflectionClass::getProperties() 필터링 예제
이 예는 기본적으로 개인 속성을 건너뛰는 선택적 filter
매개변수의 사용법을 보여줍니다.
<?php
class Foo {
public $foo = 1;
protected $bar = 2;
private $baz = 3;
}
$foo = new Foo();
$reflect = new ReflectionClass($foo);
$props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
foreach ($props as $prop) {
print $prop->getName() . "\n";
}
var_dump($props);
?>
위의 예는 다음과 유사한 결과를 출력합니다.
foo bar array(2) { [0]=> object(ReflectionProperty)#3 (2) { ["name"]=> string(3) "foo" ["class"]=> string(3) "Foo" } [1]=> object(ReflectionProperty)#4 (2) { ["name"]=> string(3) "bar" ["class"]=> string(3) "Foo" } }
기타
- ReflectionClass::getProperty() - 클래스 속성에 대한 ReflectionProperty를 가져옵니다.
- ReflectionProperty
- ReflectionProperty modifier constants