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);');
精彩评论