
ReflectionMethod::invoke를 사용하여 메소드를 호출할 때, 인자를 지정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$reflectionMethod = new ReflectionMethod('클래스명', 'sayHello');
$reflectionMethod->invoke($객체, '이름', 20);
위 예시에서 '클래스명'은 sayHello 메소드를 소유한 클래스의 이름을, '객체'는 sayHello 메소드를 호출할 객체를, '이름'과 20은 sayHello 메소드의 인자를 지정합니다.
또한, 인자를 배열로 지정할 수도 있습니다.
#hostingforum.kr
php
$reflectionMethod = new ReflectionMethod('클래스명', 'sayHello');
$reflectionMethod->invoke($객체, ['이름', 20]);
위 예시에서 인자를 배열로 지정하여 sayHello 메소드를 호출할 수 있습니다.
2025-04-19 10:07