002.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. --TEST--
  2. func_get_arg() tests
  3. --FILE--
  4. <?php
  5. function test1() {
  6. try {
  7. var_dump(func_get_arg(-10));
  8. } catch (\ValueError $e) {
  9. echo $e->getMessage() . \PHP_EOL;
  10. }
  11. try {
  12. var_dump(func_get_arg(0));
  13. } catch (\Error $e) {
  14. echo $e->getMessage() . \PHP_EOL;
  15. }
  16. try {
  17. var_dump(func_get_arg(1));
  18. } catch (\Error $e) {
  19. echo $e->getMessage() . \PHP_EOL;
  20. }
  21. }
  22. function test2($a) {
  23. try {
  24. var_dump(func_get_arg(0));
  25. } catch (\Error $e) {
  26. echo $e->getMessage() . \PHP_EOL;
  27. }
  28. try {
  29. var_dump(func_get_arg(1));
  30. } catch (\Error $e) {
  31. echo $e->getMessage() . \PHP_EOL;
  32. }
  33. }
  34. function test3($a, $b) {
  35. try {
  36. var_dump(func_get_arg(0));
  37. } catch (\Error $e) {
  38. echo $e->getMessage() . \PHP_EOL;
  39. }
  40. try {
  41. var_dump(func_get_arg(1));
  42. } catch (\Error $e) {
  43. echo $e->getMessage() . \PHP_EOL;
  44. }
  45. try {
  46. var_dump(func_get_arg(2));
  47. } catch (\Error $e) {
  48. echo $e->getMessage() . \PHP_EOL;
  49. }
  50. }
  51. test1();
  52. test1(10);
  53. test2(1);
  54. try {
  55. test2();
  56. } catch (Throwable $e) {
  57. echo "Exception: " . $e->getMessage() . "\n";
  58. }
  59. test3(1,2);
  60. call_user_func("test1");
  61. try {
  62. call_user_func("test3", 1);
  63. } catch (Throwable $e) {
  64. echo "Exception: " . $e->getMessage() . "\n";
  65. }
  66. call_user_func("test3", 1, 2);
  67. class test {
  68. static function test1($a) {
  69. try {
  70. var_dump(func_get_arg(0));
  71. } catch (\Error $e) {
  72. echo $e->getMessage() . \PHP_EOL;
  73. }
  74. try {
  75. var_dump(func_get_arg(1));
  76. } catch (\Error $e) {
  77. echo $e->getMessage() . \PHP_EOL;
  78. }
  79. }
  80. }
  81. test::test1(1);
  82. try {
  83. var_dump(func_get_arg(1));
  84. } catch (\Error $e) {
  85. echo $e->getMessage() . \PHP_EOL;
  86. }
  87. echo "Done\n";
  88. ?>
  89. --EXPECTF--
  90. func_get_arg(): Argument #1 ($position) must be greater than or equal to 0
  91. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  92. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  93. func_get_arg(): Argument #1 ($position) must be greater than or equal to 0
  94. int(10)
  95. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  96. int(1)
  97. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  98. Exception: Too few arguments to function test2(), 0 passed in %s002.php on line %d and exactly 1 expected
  99. int(1)
  100. int(2)
  101. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  102. func_get_arg(): Argument #1 ($position) must be greater than or equal to 0
  103. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  104. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  105. Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
  106. int(1)
  107. int(2)
  108. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  109. int(1)
  110. func_get_arg(): Argument #1 ($position) must be less than the number of the arguments passed to the currently executed function
  111. func_get_arg() cannot be called from the global scope
  112. Done