002.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --TEST--
  2. func_get_arg() tests
  3. --FILE--
  4. <?php
  5. function test1() {
  6. var_dump(func_get_arg(-10));
  7. var_dump(func_get_arg(0));
  8. var_dump(func_get_arg(1));
  9. }
  10. function test2($a) {
  11. var_dump(func_get_arg(0));
  12. var_dump(func_get_arg(1));
  13. }
  14. function test3($a, $b) {
  15. var_dump(func_get_arg(0));
  16. var_dump(func_get_arg(1));
  17. var_dump(func_get_arg(2));
  18. }
  19. test1();
  20. test1(10);
  21. test2(1);
  22. try {
  23. test2();
  24. } catch (Throwable $e) {
  25. echo "Exception: " . $e->getMessage() . "\n";
  26. }
  27. test3(1,2);
  28. call_user_func("test1");
  29. try {
  30. call_user_func("test3", 1);
  31. } catch (Throwable $e) {
  32. echo "Exception: " . $e->getMessage() . "\n";
  33. }
  34. call_user_func("test3", 1, 2);
  35. class test {
  36. static function test1($a) {
  37. var_dump(func_get_arg(0));
  38. var_dump(func_get_arg(1));
  39. }
  40. }
  41. test::test1(1);
  42. var_dump(func_get_arg(1));
  43. echo "Done\n";
  44. ?>
  45. --EXPECTF--
  46. Warning: func_get_arg(): The argument number should be >= 0 in %s on line %d
  47. bool(false)
  48. Warning: func_get_arg(): Argument 0 not passed to function in %s on line %d
  49. bool(false)
  50. Warning: func_get_arg(): Argument 1 not passed to function in %s on line %d
  51. bool(false)
  52. Warning: func_get_arg(): The argument number should be >= 0 in %s on line %d
  53. bool(false)
  54. int(10)
  55. Warning: func_get_arg(): Argument 1 not passed to function in %s on line %d
  56. bool(false)
  57. int(1)
  58. Warning: func_get_arg(): Argument 1 not passed to function in %s on line %d
  59. bool(false)
  60. Exception: Too few arguments to function test2(), 0 passed in %s002.php on line %d and exactly 1 expected
  61. int(1)
  62. int(2)
  63. Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d
  64. bool(false)
  65. Warning: func_get_arg(): The argument number should be >= 0 in %s on line %d
  66. bool(false)
  67. Warning: func_get_arg(): Argument 0 not passed to function in %s on line %d
  68. bool(false)
  69. Warning: func_get_arg(): Argument 1 not passed to function in %s on line %d
  70. bool(false)
  71. Exception: Too few arguments to function test3(), 1 passed in %s002.php on line %d and exactly 2 expected
  72. int(1)
  73. int(2)
  74. Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d
  75. bool(false)
  76. int(1)
  77. Warning: func_get_arg(): Argument 1 not passed to function in %s on line %d
  78. bool(false)
  79. Warning: func_get_arg(): Called from the global scope - no function context in %s on line %d
  80. bool(false)
  81. Done