
ReflectionClass::isIterable은 PHP 7.1에서 추가된 메서드입니다. 이 메서드는 객체가 반복 가능한지 여부를 확인합니다. 반복 가능한 객체는 foreach 문을 사용할 수 있습니다.
isIterable은 array, object, Traversable 인터페이스를 구현한 객체에 대해 true를 반환합니다. 예를 들어, array $arr = [1, 2, 3]; 에서 $arr은 반복 가능한 객체입니다.
이 메서드는 ReflectionClass를 사용하여 클래스의 프로퍼티나 메서드에 대해 반복 가능한 객체를 검사할 때 유용합니다. 예를 들어, 클래스에 반복 가능한 프로퍼티가 있는지 확인하고 싶을 때 사용할 수 있습니다.
#hostingforum.kr
php
class MyClass {
public $arr = [1, 2, 3];
}
$reflectionClass = new ReflectionClass('MyClass');
if ($reflectionClass->isIterable($reflectionClass->getProperty('arr'))) {
echo "arr 프로퍼티는 반복 가능한 객체입니다.";
} else {
echo "arr 프로퍼티는 반복 불가능한 객체입니다.";
}
이 예제에서는 MyClass 클래스의 arr 프로퍼티가 반복 가능한 객체인지 확인합니다.
2025-03-08 16:01