1--TEST-- 2func_num_args() tests 3--FILE-- 4<?php 5 6function test1() { 7 var_dump(func_num_args()); 8} 9 10function test2($a) { 11 var_dump(func_num_args()); 12} 13 14function test3($a, $b) { 15 var_dump(func_num_args()); 16} 17 18test1(); 19test2(1); 20try { 21 test2(); 22} catch (Throwable $e) { 23 echo "Exception: " . $e->getMessage() . "\n"; 24} 25 26test3(1,2); 27 28call_user_func("test1"); 29try { 30 call_user_func("test3", 1); 31} catch (Throwable $e) { 32 echo "Exception: " . $e->getMessage() . "\n"; 33} 34call_user_func("test3", 1, 2); 35 36class test { 37 static function test1($a) { 38 var_dump(func_num_args()); 39 } 40} 41 42test::test1(1); 43var_dump(func_num_args()); 44 45echo "Done\n"; 46?> 47--EXPECTF-- 48int(0) 49int(1) 50Exception: Too few arguments to function test2(), 0 passed in %s001.php on line 18 and exactly 1 expected 51int(2) 52int(0) 53Exception: Too few arguments to function test3(), 1 passed in %s001.php on line 27 and exactly 2 expected 54int(2) 55int(1) 56 57Warning: func_num_args(): Called from the global scope - no function context in %s on line %d 58int(-1) 59Done 60