Reflection ReflectionMethod::__construct
(PHP 5, PHP 7, PHP 8)
ReflectionMethod::__construct — ReflectionMethod 생성
설명
public ReflectionMethod::__construct(object|string $objectOrMethod
, string $method
)
대체 서명(명명된 인수에서는 지원되지 않음):
public ReflectionMethod::__construct(string $classMethod
)
새로운 ReflectionMethod를 생성합니다.
매개변수
objectOrMethod
- 메서드를 포함하는 클래스 이름 또는 개체(클래스의 인스턴스)입니다.
method
- 메서드의 이름입니다.
classMethod
- ::로 구분된 클래스 이름과 메소드 이름.
오류/예외
지정된 메서드가 없으면 ReflectionException이 발생합니다.
Examples
예제 #1 ReflectionMethod::__construct() 예제
<?php
class Counter
{
private static $c = 0;
/**
* Increment counter
*
* @final
* @static
* @access public
* @return int
*/
final public static function increment()
{
return ++self::$c;
}
}
// Create an instance of the ReflectionMethod class
$method = new ReflectionMethod('Counter', 'increment');
// Print out basic information
printf(
"===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n" .
" declared in %s\n" .
" lines %d to %d\n" .
" having the modifiers %d[%s]\n",
$method->isInternal() ? 'internal' : 'user-defined',
$method->isAbstract() ? ' abstract' : '',
$method->isFinal() ? ' final' : '',
$method->isPublic() ? ' public' : '',
$method->isPrivate() ? ' private' : '',
$method->isProtected() ? ' protected' : '',
$method->isStatic() ? ' static' : '',
$method->getName(),
$method->isConstructor() ? 'the constructor' : 'a regular method',
$method->getFileName(),
$method->getStartLine(),
$method->getEndline(),
$method->getModifiers(),
implode(' ', Reflection::getModifierNames($method->getModifiers()))
);
// Print documentation comment
printf("---> Documentation:\n %s\n", var_export($method->getDocComment(), true));
// Print static variables if existant
if ($statics= $method->getStaticVariables()) {
printf("---> Static variables: %s\n", var_export($statics, true));
}
// Invoke the method
printf("---> Invocation results in: ");
var_dump($method->invoke(NULL));
?>
위의 예는 다음과 유사한 결과를 출력합니다.
===> The user-defined final public static method 'increment' (which is a regular method) declared in /Users/philip/cvs/phpdoc/test.php lines 14 to 17 having the modifiers 261[final public static] ---> Documentation: '/** * Increment counter * * @final * @static * @access public * @return int */' ---> Invocation results in: int(1)
기타
- ReflectionMethod::export() - reflection 메서드 내보내기
- Constructors