Here is another example with a parameter:
<?php
function hello_world($word) {
echo "Original Hello World: $word\n</br>";
}
$helloWorld = 'echo "Redefined Hello World: $word\n</br>";';
hello_world('test1');
runkit_function_redefine('hello_world', '$word', $helloWorld);
hello_world('test2');
?>
runkit_function_redefine
(PECL runkit:0.7-0.9)
runkit_function_redefine — 関数の定義を新しい実装で置き換える
説明
bool runkit_function_redefine
( string $funcname
, string $arglist
, string $code
)
注意: デフォルトでは、 削除・リネーム・変更が可能なのはユーザ定義関数だけです。組み込み関数を オーバーライドするには、php.ini で runkit.internal_override を有効にする必要があります。
パラメータ
- funcname
-
再定義する関数の名前。
- arglist
-
再定義後の関数が受け取る引数のリスト。
- code
-
新しい実装コード。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例1 runkit_function_redefine() の例
<?php
function testme() {
echo "Original Testme Implementation\n";
}
testme();
runkit_function_redefine('testme','','echo "New Testme Implementation\n";');
testme();
?>
上の例の出力は以下となります。
Original Testme Implementation New Testme Implementation
runkit_function_redefine
corentin dot delorme at linagora dot com
05-Sep-2007 10:04
05-Sep-2007 10:04
