
속성이 없는 경우 ReflectionProperty::getName() 메서드는 PHP Notice: Undefined property: TestClass::$nonExistentProperty 오류를 발생시키지 않고, 속성이 존재하지 않음을 나타내는 빈 문자열을 반환합니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class TestClass {
public $testProperty;
}
$reflection = new ReflectionClass('TestClass');
$property = $reflection->getProperty('nonExistentProperty');
var_dump($property->getName()); // string(0) ""
이러한 동작은 ReflectionProperty 클래스의 디자인 결정에 따라서 발생합니다. ReflectionProperty 클래스는 속성이 존재하지 않더라도 속성 이름을 반환하도록 설계되어 있습니다.
2025-06-12 10:07