
ReflectionClass::__toString 메소드는 ReflectionClass 객체를 문자열로 반환합니다.
예를 들어, ReflectionClass::getName() 메소드의 반환값을 포함한 문자열이 반환됩니다.
__toString 메소드는 다음과 같은 상황에서 호출됩니다.
- var_dump() 함수를 사용할 때
- print_r() 함수를 사용할 때
- echo 문을 사용할 때
__toString 메소드를 override하는 방법은 다음과 같습니다.
- ReflectionClass를 상속받은 클래스에서 __toString 메소드를 오버라이드합니다.
- ReflectionClass::getName() 메소드와 같은 이름의 메소드를 오버라이드합니다.
예를 들어, 다음과 같이 __toString 메소드를 오버라이드할 수 있습니다.
#hostingforum.kr
php
class MyReflectionClass extends ReflectionClass {
public function __toString() {
return 'MyReflectionClass: ' . parent::__toString();
}
}
이러한 방법으로 __toString 메소드를 오버라이드할 수 있습니다.
2025-07-09 16:09