runkit_function_redefine

(PECL runkit >= 0.7.0)

runkit_function_redefine 関数の定義を新しい実装で置き換える

説明

bool runkit_function_redefine ( string $funcname , string $arglist , string $code )

注意: デフォルトでは、 削除・リネーム・変更が可能なのはユーザー定義関数だけです。組み込み関数を オーバーライドするには、php.inirunkit.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

参考

add a note add a note

User Contributed Notes 2 notes

up
11
lucato at gmail dot com
5 years ago
Note to users: language constructs (eval, die, exit, isset, unset, echo etc.) which might be confused with functions, cannot be renamed or redefined even with runkit.internal_override.
up
5
corentin dot delorme at linagora dot com
9 years ago
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');

?>
To Top