runkit的使用(转)

上一篇 / 下一篇  2012-02-06 16:05:07 / 个人分类:php

转自:http://shendongming.blog.51cto.com/458802/759403

函数的重定义

runkit_function_redefine

<?php
function testme
() {
  echo 
"Original Testme Implementation\n"
;
}
testme
();
runkit_function_redefine('testme','','echo "New Testme Implementation\n";'
);
testme
();
?>

 

方法的重定义

 

runkit_method_redefine

 

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

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

// output Example::foo() (before redefine)
echo "Before: " $e->foo();

// Redefine the 'foo' method
runkit_method_redefine(
    
'Example',
    
'foo',
    
'',
    
'return "bar!\n";',
    
RUNKIT_ACC_PUBLIC
);

// output Example::foo() (after redefine)
echo "After: " $e->foo();
?>

 

方法的重命名

 

runkit_method_rename

 

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

// Rename the 'foo' method to 'bar'
runkit_method_rename(
    
'Example',
    
'foo',
    
'bar'
);

// output renamed function
echo Example::bar();
?>

TAG:

 

评分:0

我来说两句

Open Toolbar