001.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. try {
  36. func_num_args();
  37. } catch (Error $exception) {
  38. echo $exception->getMessage() . "\n";
  39. }
  40. echo "Done\n";
  41. ?>
  42. --EXPECTF--
  43. int(0)
  44. int(1)
  45. Exception: Too few arguments to function test2(), 0 passed in %s on line %d and exactly 1 expected
  46. int(2)
  47. int(0)
  48. Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
  49. int(2)
  50. int(1)
  51. func_num_args() must be called from a function context
  52. Done