下面的代码工作正常。
LibraryTests::TestGetServer();
获取 LibraryTests 中的函数数组并运行它们:
$methods = get_class_methods('LibraryTests');
foreach ($methods as $method) {
call_user_func('LibraryTests::' . $method . '()' );
}
这会引发错误:Warning: call_user_func(LibraryTests::TestGetServer()) [function.call-user-func]: First argument is expected to be a valid callback
这是被调用的类:
class LibraryTests extends TestUnit {
function TestGetServer() {
TestUnit::AssertEqual(GetServer(), "localhost/");
}
.
.
.
怎么修?
在 PHP 5.2.8 中工作。
(从 PHP 5.2.3 开始):
$methods = get_class_methods('LibraryTests');
foreach ($methods as $method) {
call_user_func('LibraryTests::' . $method);
}
或者(之前):
$methods = get_class_methods('LibraryTests');
foreach ($methods as $method) {
call_user_func(array('LibraryTests', $method));
}
See call_user_funcDocs http://php.net/call_user_func and the Callback Pseudo-TypeDocs http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)