PHP8 runkit7_function_add — 添加一個新函數(shù),類似于 create_function()

2023-09-22 15:44 更新

(PECL runkit7 >= Unknown)

runkit7_function_add — 添加一個新函數(shù),類似于 create_function()。

說明

runkit7_function_add(
    string $function_name,
    string $argument_list,
    string $code,
    bool $return_by_reference = null,
    string $doc_comment = null,
    string $return_type = ?,
    bool $is_strict = ?
): bool

runkit7_function_add(
    string $function_name,
    Closure $closure,
    string $doc_comment = null,
    string $return_type = ?,
    bool $is_strict = ?
): bool

參數(shù)

function_name

要創(chuàng)建的函數(shù)的名稱。

argument_list

逗號分隔的參數(shù)列表。

code

構(gòu)成該函數(shù)的代碼。

closure

定義函數(shù)的閉包。

return_by_reference

函數(shù)是否應(yīng)該返回引用。

doc_comment

函數(shù)的文檔注釋。

return_type

函數(shù)的返回類型。

is_strict

函數(shù)是否應(yīng)該表現(xiàn)得像在 ?strict_types=1? 的文件中聲明一樣。

返回值

成功時返回 true, 或者在失敗時返回 false。

示例

示例 #1 A runkit7_function_add() example

<?php
runkit7_function_add('testme','$a,$b','echo "The value of a is $a\n"; echo "The value of b is $b\n";');
testme(1,2);
?>

以上示例會輸出:

The value of a is 1
The value of b is 2

參見

  • create_function() - 通過執(zhí)行代碼字符串創(chuàng)建動態(tài)函數(shù)
  • runkit7_function_redefine() - 用新的實現(xiàn)替換函數(shù)定義
  • runkit7_function_copy() - 將一個函數(shù)復(fù)制到一個新的函數(shù)名
  • runkit7_function_rename() - 更改函數(shù)的名稱
  • runkit7_function_remove() - 移除一個函數(shù)定義
  • runkit7_method_add() - 動態(tài)地向給定的類添加一個新方法


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號