runkit7_method_redefine
(PECL runkit7 >= Unknown)
runkit7_method_redefine — 주어진 메소드의 코드를 동적으로 변경
설명
runkit7_method_redefine( string $class_name, string $method_name, string $argument_list, string $code, int $flags = RUNKIT7_ACC_PUBLIC, string $doc_comment = null, string $return_type = ?, bool $is_strict = ? ): bool
runkit7_method_redefine( string $class_name, string $method_name, Closure $closure, int $flags = RUNKIT7_ACC_PUBLIC, string $doc_comment = null, string $return_type = ?, bool $is_strict = ? ): bool
매개변수
class_name
- 메서드를 재정의할 클래스
method_name
- 재정의할 메서드의 이름
argument_list
- 재정의된 메서드에 대한 쉼표로 구분된 인수 목록
code
method_name
이 호출될 때 평가될 새 코드closure
- 메서드를 정의하는 클로저.
flags
- 재정의된 메서드는
RUNKIT7_ACC_PUBLIC
,RUNKIT7_ACC_PROTECTED
또는RUNKIT7_ACC_PRIVATE
가 될 수 있으며 선택적으로 비트 OR을 통해RUNKIT7_ACC_STATIC
와 결합됩니다. doc_comment
- 메서드의 문서 주석입니다.
return_type
- 메서드의 반환 유형입니다.
is_strict
- 메서드가
strict_types=1
인 파일에서 선언된 것처럼 동작하는지 여부.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 runkit7_method_redefine() 예제
<?php
class Example {
function foo() {
return "foo!\n";
}
}
// create an Example object
$e = new Example();
// output Example::foo() (before redefine)
echo "Before: " . $e->foo();
// Redefine the 'foo' method
runkit7_method_redefine(
'Example',
'foo',
'',
'return "bar!\n";',
RUNKIT7_ACC_PUBLIC
);
// output Example::foo() (after redefine)
echo "After: " . $e->foo();
?>
위의 예는 다음을 출력합니다.
Before: foo! After: bar!
기타
- runkit7_method_add() - 주어진 클래스에 새로운 메소드를 동적으로 추가
- runkit7_method_copy() - 클래스에서 다른 클래스로 메소드 복사
- runkit7_method_remove() - 주어진 메소드를 동적으로 제거
- runkit7_method_rename() - 주어진 메소드의 이름을 동적으로 변경
- runkit7_function_redefine() - 함수 정의를 새 구현으로 교체