1 <?php 2 3 function demo( $num, $n) { 4 for ( $i = 0; $i < $num; $i++) { 5 // if ($n($i)) 6 if ( call_user_func_array( $n, array( $i))) 7 continue; 8 echo $i.'<br>'; 9 } 10 } 11 12 class Filter 13 { 14 function one( $i) 15 { 16 if ( $i == strrev( $i)) 17 return true; 18 else 19 return false; 20 } 21 22 static function two( $i) 23 { 24 if ( $i%3 == 0) 25 return true; 26 else 27 return false; 28 } 29 } 30 31 function test( $i) { 32 if ( $i%3 == 0) 33 return true; 34 else 35 return false; 36 } 37 38 // demo(500, 'test'); 39 40 //demo(500, array('new Filter()', 'one'); 41 // 42 //demo(500, array(new Filter(), 'one')); 43 // 44 demo(500, array('Filter', 'two'));
call_user_func(array($class, $method));
// 其中如果$class传入的是一个实例化的对象,那么调用不是静态方法(static),传入的是字符串那么调用的是静态方法(static)