
ReflectionClass::isIterable() 메소드는 객체가 반복 가능한지 확인합니다. 이 메소드는 객체가 반복 가능한지 여부를 boolean 값으로 반환합니다.
이 메소드는 false를 반환하는 상황은 다음과 같습니다.
- 객체가 null 인 경우
- 객체가 배열이 아닌 경우 (예: 객체는 객체 인스턴스이거나 인터페이스 인스턴스일 수 있습니다.)
- 객체가 반복 가능하지 않은 경우 (예: 객체가 인터페이스인 경우, 인터페이스는 반복 가능하지 않습니다.)
예를 들어, 다음 코드는 ReflectionClass::isIterable() 메소드의 동작을 보여줍니다.
#hostingforum.kr
php
class NonIterableObject {
}
$reflectionClass = new ReflectionClass('NonIterableObject');
echo $reflectionClass->isIterable() ? 'true' : 'false'; // false
$reflectionClass = new ReflectionClass('array');
echo $reflectionClass->isIterable() ? 'true' : 'false'; // true
$reflectionClass = new ReflectionClass(null);
echo $reflectionClass->isIterable() ? 'true' : 'false'; // false
이 예제에서, NonIterableObject 클래스는 반복 가능하지 않습니다. 반면, array 클래스는 반복 가능합니다. null 인 경우 ReflectionClass::isIterable() 메소드는 false를 반환합니다.
2025-06-08 20:34