开发者

Creating a function or classes aliases without uses eval

开发者 https://www.devze.com 2023-03-19 01:47 出处:网络
I want know if, on PHP, is possible to create a function (or class) aliases without uses eval() and only with native methods. Eval don\'t is recomended for some developers and I\'m building a framewor

I want know if, on PHP, is possible to create a function (or class) aliases without uses eval() and only with native methods. Eval don't is recomended for some developers and I'm building a framework -- I prefer don't uses eval too.

Currently, I do something like:

    eval('function aliases_x(){ return x(); }');
开发者_运维百科

It's all!

Bye.

Edit: sorry for miss that... I need do it at an automatic method.

Example:

function create_aliases($real_method, $new_name) { ... }

create_aliases('x', 'aliasses_x');


Well, to alias a class, you can use class_alias. To alias a function you are a little more limited. Most suggestions I've seen suggested the use of create_function or the new anonymous function syntax

$aliases_x = function($v) { return x($v); };
// OR
$aliases_x = create_function('$v', 'return x($v);');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号