xref: /PHP-8.1/Zend/tests/named_params/basic.phpt (revision d92229d8)
1--TEST--
2Basic test
3--FILE--
4<?php
5
6function test($a, $b, $c = "c", $d = "d", $e = "e") {
7    echo "a=$a, b=$b, c=$c, d=$d, e=$e\n";
8}
9
10function test3(&$a, &$b, &$c = "c", &$d = "d", &$e = "e") {
11    echo "a=$a, b=$b, c=$c, d=$d, e=$e\n";
12}
13
14function &id($x) {
15    return $x;
16}
17
18$a = "A"; $b = "B"; $c = "C"; $d = "D"; $e = "E";
19
20echo "SEND_VAL:\n";
21test("A", "B", "C", d: "D", e: "E");
22test("A", "B", "C", e: "E", d: "D");
23test(e: "E", a: "A", d: "D", b: "B", c: "C");
24test("A", "B", "C", e: "E");
25
26echo "SEND_VAL_EX:\n";
27test2("A", "B", "C", d: "D", e: "E");
28test2("A", "B", "C", e: "E", d: "D");
29test2(e: "E", a: "A", d: "D", b: "B", c: "C");
30test2("A", "B", "C", e: "E");
31
32echo "SEND_VAR:\n";
33test($a, $b, $c, d: $d, e: $e);
34test($a, $b, $c, e: $e, d: $d);
35test(e: $e, a: $a, d: $d, b: $b, c: $c);
36test(a: $a, b: $b, c: $c, e: $e);
37
38echo "SEND_VAR_EX:\n";
39test2($a, $b, $c, d: $d, e: $e);
40test2($a, $b, $c, e: $e, d: $d);
41test2(e: $e, a: $a, d: $d, b: $b, c: $c);
42test2(a: $a, b: $b, c: $c, e: $e);
43
44echo "SEND_VAR_NO_REF:\n";
45test3(id("A"), id("B"), id("C"), d: id("D"), e: id("E"));
46test3(id("A"), id("B"), id("C"), e: id("E"), d: id("D"));
47test3(e: id("E"), a: id("A"), d: id("D"), b: id("B"), c: id("C"));
48test3(id("A"), id("B"), id("C"), e: id("E"));
49
50echo "SEND_VAR_NO_REF_EX:\n";
51test4(id("A"), id("B"), id("C"), d: id("D"), e: id("E"));
52test4(id("A"), id("B"), id("C"), e: id("E"), d: id("D"));
53test4(e: id("E"), a: id("A"), d: id("D"), b: id("B"), c: id("C"));
54test4(id("A"), id("B"), id("C"), e: id("E"));
55
56echo "SEND_REF:\n";
57test3($a, $b, $c, d: $d, e: $e);
58test3($a, $b, $c, e: $e, d: $d);
59test3(e: $e, a: $a, d: $d, b: $b, c: $c);
60test3(a: $a, b: $b, c: $c, e: $e);
61
62function test2($a, $b, $c = "c", $d = "d", $e = "e") {
63    echo "a=$a, b=$b, c=$c, d=$d, e=$e\n";
64}
65
66function test4(&$a, &$b, &$c = "c", &$d = "d", &$e = "e") {
67    echo "a=$a, b=$b, c=$c, d=$d, e=$e\n";
68}
69
70?>
71--EXPECT--
72SEND_VAL:
73a=A, b=B, c=C, d=D, e=E
74a=A, b=B, c=C, d=D, e=E
75a=A, b=B, c=C, d=D, e=E
76a=A, b=B, c=C, d=d, e=E
77SEND_VAL_EX:
78a=A, b=B, c=C, d=D, e=E
79a=A, b=B, c=C, d=D, e=E
80a=A, b=B, c=C, d=D, e=E
81a=A, b=B, c=C, d=d, e=E
82SEND_VAR:
83a=A, b=B, c=C, d=D, e=E
84a=A, b=B, c=C, d=D, e=E
85a=A, b=B, c=C, d=D, e=E
86a=A, b=B, c=C, d=d, e=E
87SEND_VAR_EX:
88a=A, b=B, c=C, d=D, e=E
89a=A, b=B, c=C, d=D, e=E
90a=A, b=B, c=C, d=D, e=E
91a=A, b=B, c=C, d=d, e=E
92SEND_VAR_NO_REF:
93a=A, b=B, c=C, d=D, e=E
94a=A, b=B, c=C, d=D, e=E
95a=A, b=B, c=C, d=D, e=E
96a=A, b=B, c=C, d=d, e=E
97SEND_VAR_NO_REF_EX:
98a=A, b=B, c=C, d=D, e=E
99a=A, b=B, c=C, d=D, e=E
100a=A, b=B, c=C, d=D, e=E
101a=A, b=B, c=C, d=d, e=E
102SEND_REF:
103a=A, b=B, c=C, d=D, e=E
104a=A, b=B, c=C, d=D, e=E
105a=A, b=B, c=C, d=D, e=E
106a=A, b=B, c=C, d=d, e=E
107