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); 43 44try { 45 func_num_args(); 46} catch (Error $exception) { 47 echo $exception->getMessage() . "\n"; 48} 49 50echo "Done\n"; 51?> 52--EXPECTF-- 53int(0) 54int(1) 55Exception: Too few arguments to function test2(), 0 passed in %s on line %d and exactly 1 expected 56int(2) 57int(0) 58Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected 59int(2) 60int(1) 61func_num_args() must be called from a function context 62Done 63