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!
                

기타