作为 PHP 新手,并且对这个“函数包装器”有很多依赖,我想我会得到一些意见和一些反馈。如果可能的话,我想得到大约五条评论。
现在在你问之前,我有很多理由想要包装其他(WordPress)功能,主要是无忧升级。能够为每个函数定义设置自定义名称对我来说也很重要,因此$wrap array
.
但是我跑题了,这看起来可以接受并且相对防弹吗?
function core_oo( $function )
{
$args = array_slice( func_get_args(), 1 );
$wrap = array
(
'comment' => 'the_comment',
'comments' => 'have_comments',
'post' => 'the_post',
'posts' => 'have_posts'
);
return call_user_func_array( $wrap[ $function ], $args );
}
...并且该函数将被称为...
core_oo( 'post', 'arg1', 'arg2' );
非常感谢!
编辑:
根据下面混乱的建议,这是将 $wrap 声明为静态的正确方法吗?
static $wrap = array
( ...