001.phpt 1008 B

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