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)
}
}
有关更多信息,请查看