
ReflectionMethod::invoke 메서드를 사용하여 클래스의 메서드를 호출할 때, 매개 변수를 전달하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$reflectionMethod = $reflectionClass->getMethod('myMethod');
$reflectionMethod->invoke($myInstance, '매개변수1', '매개변수2');
위 코드에서 `$myInstance`는 `MyClass`의 인스턴스여야 합니다. `myMethod` 메서드에 전달할 매개 변수는 두 번째 인자로 전달됩니다.
이러한 방법으로, `myMethod` 메서드에 여러 개의 매개 변수를 전달할 수 있습니다.
#hostingforum.kr
php
$reflectionMethod->invoke($myInstance, '매개변수1', '매개변수2', '매개변수3', '매개변수4');
만약 `myMethod` 메서드에 매개 변수가 없다면, 다음과 같이 호출할 수 있습니다.
#hostingforum.kr
php
$reflectionMethod->invoke($myInstance);
2025-05-10 20:46