runkit7_method_add

(PECL runkit7 >= Unknown)

runkit7_method_add — 주어진 클래스에 새로운 메소드를 동적으로 추가


설명

runkit7_method_add(
    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_add(
    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_add() 예제

                  
<?php
class Example {
    function foo() {
        echo "foo!\n";
    }
}

// create an Example object
$e = new Example();

// Add a new public method
runkit7_method_add(
    'Example',
    'add',
    '$num1, $num2',
    'return $num1 + $num2;',
    RUNKIT7_ACC_PUBLIC
);

// add 12 + 4
echo $e->add(12, 4);
?>
                  
                

위의 예는 다음을 출력합니다.

16
                

기타