Mã sau hoạt động tốt.Làm thế nào để sử dụng call_user_func cho phương thức lớp tĩnh?
LibraryTests::TestGetServer();
Lấy loạt các chức năng trong LibraryTests và chạy chúng:
$methods = get_class_methods('LibraryTests');
foreach ($methods as $method) {
call_user_func('LibraryTests::' . $method . '()');
}
này ném một lỗi: Warning: call_user_func(LibraryTests::TestGetServer()) [function.call-user-func]: First argument is expected to be a valid callback
Đây là lớp học mà được gọi là:
class LibraryTests extends TestUnit {
function TestGetServer() {
TestUnit::AssertEqual(GetServer(), "localhost/");
}
.
.
.
Cách khắc phục?
Làm việc với PHP 5.2.8.
Không nối thêm '()' nếu hàm không có tham số – m13r