Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何调用CodeIgniter单元测试中使用的所有通用名函数_Php_Codeigniter - Fatal编程技术网

Php 如何调用CodeIgniter单元测试中使用的所有通用名函数

Php 如何调用CodeIgniter单元测试中使用的所有通用名函数,php,codeigniter,Php,Codeigniter,很抱歉标题不好,但希望我能用一些代码解释一下 假设我有以下功能: <?php function helloTest() { echo 'hello'; } function worldTest() { echo 'world'; } function helloworld() { // call all functions with 'Test' } ?> helloworld函数是否可以调用最后命名为“Test”的所有函数 您应该使用php

很抱歉标题不好,但希望我能用一些代码解释一下

假设我有以下功能:

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

function worldTest()
{
    echo 'world';
}

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

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

您应该使用php函数来获取以下所有方法

$funcs = get_defined_functions();

foreach( $funcs['user'] as $f ) {
    if( strstr($f, 'Test') )
        call_user_func($f);
}
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)
    }
}
有关更多信息,请查看