在运行时修改方法/函数 [英] modify a method/function at runtime

查看:46
本文介绍了在运行时修改方法/函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看php反射方法,我想做的是在方法打开之后和任何返回值之前注入一些代码,例如我想改变:

I've been looking at the php reflection methods, what i want to do is inject some code after the method is opened and before any return value, for example i want to change:

function foo($bar)
{
    $foo = $bar ;
    return $foo ;
}

并向其中注入一些代码,例如:

And inject some code into it like:

function foo($bar)
{
    //some code here
    $foo = $bar ;
    //some code here
    return $foo ;
}

可能吗?

推荐答案

查看 anonymous功能.如果您可以运行 PHP 5.3,那可能更符合您要执行的操作.

Look into anonymous functions. If you can run PHP 5.3 that might be more along the lines of what you're trying to do.

这篇关于在运行时修改方法/函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆