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