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