W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
(PECL runkit7 >= Unknown)
runkit7_method_add — 動(dòng)態(tài)地向給定類添加一個(gè)新方法。
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
逗號(hào)分隔的參數(shù)列表,用于新創(chuàng)建的方法
code
方法被調(diào)用時(shí)要評(píng)估的代碼
closure
定義方法的閉包
flags
要?jiǎng)?chuàng)建的方法類型,可以是RUNKIT7_ACC_PUBLIC、RUNKIT7_ACC_PROTECTED或RUNKIT7_ACC_PRIVATE,可以選擇通過(guò)位運(yùn)算與RUNKIT7_ACC_STATIC組合使用
doc_comment
方法的文檔注釋
return_type
方法的返回類型
is_strict
方法是否表現(xiàn)得像是在啟用 ?strict_types=1
? 的文件中聲明的
成功時(shí)返回 true, 或者在失敗時(shí)返回 false。
示例 #1 runkit7_method_add() example
<?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);
?>
以上示例會(huì)輸出:
16
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: