003.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. func_get_args() tests
  3. --FILE--
  4. <?php
  5. function test1() {
  6. var_dump(func_get_args());
  7. }
  8. function test2($a) {
  9. var_dump(func_get_args());
  10. }
  11. function test3($a, $b) {
  12. var_dump(func_get_args());
  13. }
  14. test1();
  15. test1(10);
  16. test2(1);
  17. try {
  18. test2();
  19. } catch (Throwable $e) {
  20. echo "Exception: " . $e->getMessage() . "\n";
  21. }
  22. test3(1,2);
  23. call_user_func("test1");
  24. try {
  25. call_user_func("test3", 1);
  26. } catch (Throwable $e) {
  27. echo "Exception: " . $e->getMessage() . "\n";
  28. }
  29. call_user_func("test3", 1, 2);
  30. class test {
  31. static function test1($a) {
  32. var_dump(func_get_args());
  33. }
  34. }
  35. test::test1(1);
  36. try {
  37. var_dump(func_get_args());
  38. } catch (\Error $e) {
  39. echo $e->getMessage() . \PHP_EOL;
  40. }
  41. ?>
  42. --EXPECTF--
  43. array(0) {
  44. }
  45. array(1) {
  46. [0]=>
  47. int(10)
  48. }
  49. array(1) {
  50. [0]=>
  51. int(1)
  52. }
  53. Exception: Too few arguments to function test2(), 0 passed in %s003.php on line %d and exactly 1 expected
  54. array(2) {
  55. [0]=>
  56. int(1)
  57. [1]=>
  58. int(2)
  59. }
  60. array(0) {
  61. }
  62. Exception: Too few arguments to function test3(), 1 passed in %s003.php on line %d and exactly 2 expected
  63. array(2) {
  64. [0]=>
  65. int(1)
  66. [1]=>
  67. int(2)
  68. }
  69. array(1) {
  70. [0]=>
  71. int(1)
  72. }
  73. func_get_args() cannot be called from the global scope