0

抱歉标题相当糟糕,但希望我可以用一些代码来解释它。

所以可以说我有以下功能:

<?php    
function helloTest()
{
    echo 'hello';
}

function worldTest()
{
    echo 'world';
}

function helloworld()
{
    // call all functions with 'Test'
}
?>

helloworld函数是否可以调用最后命名为“测试”的所有函数?

4

2 回答 2

2
$funcs = get_defined_functions();

foreach( $funcs['user'] as $f ) {
    if( strstr($f, 'Test') )
        call_user_func($f);
}
于 2012-08-13T12:33:42.943 回答
-1

您应该使用Get All methods php 函数来获取所有方法,如下所示

function helloTest()
{
    echo 'hello';
}

function worldTest()
{
    echo 'world';
}

function helloworld()
{
    // call all functions with 'Test'
    $methods = get_defined_functions();
    $user_defined_methods = $methods['user'];
    foreach ($user_defined_methods as $method_name) 
    {
         //check with regular expressions if it's having 'Test' at end of $method_name then call that function using call_user_func($method_name)
    }
}

有关更多信息,请查看此链接

于 2012-08-13T12:35:33.483 回答