Skip to content

Commit c5de589

Browse files
committed
Throw warning is required param follows optional
1 parent 0a9bdd6 commit c5de589

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

Zend/tests/bug71428.3.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ class B { public function m(A $a = NULL, $n) { echo "B.m";} };
77
class C extends B { public function m(A $a , $n) { echo "C.m";} };
88
?>
99
--EXPECTF--
10+
Warning: Required parameter $n follows optional parameter in %s on line 3
11+
1012
Fatal error: Declaration of C::m(A $a, $n) must be compatible with B::m(?A $a, $n) in %sbug71428.3.php on line 4

Zend/tests/call_user_func_005.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var_dump(call_user_func(array('foo', 'teste')));
1818

1919
?>
2020
--EXPECTF--
21+
Warning: Required parameter $b follows optional parameter in %s on line %d
2122
string(1) "x"
2223
array(1) {
2324
[0]=>

Zend/tests/traits/bug60717.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace HTML
99
{
1010
function text($text);
1111
function attributes(array $attributes = null);
12-
function textArea(array $attributes = null, $value);
12+
function textArea(?array $attributes, $value);
1313
}
1414

1515
trait TextUTF8
@@ -19,7 +19,7 @@ namespace HTML
1919

2020
trait TextArea
2121
{
22-
function textArea(array $attributes = null, $value) {}
22+
function textArea(?array $attributes, $value) {}
2323
abstract function attributes(array $attributes = null);
2424
abstract function text($text);
2525
}

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5666,6 +5666,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
56665666
uint32_t i;
56675667
zend_op_array *op_array = CG(active_op_array);
56685668
zend_arg_info *arg_infos;
5669+
zend_bool have_optional_param = 0;
56695670

56705671
if (return_type_ast) {
56715672
/* Use op_array->arg_info[-1] for return type */
@@ -5734,10 +5735,15 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
57345735
default_node.op_type = IS_CONST;
57355736
zend_const_expr_to_zval(&default_node.u.constant, default_ast);
57365737
CG(compiler_options) = cops;
5738+
have_optional_param = 1;
57375739
} else {
57385740
opcode = ZEND_RECV;
57395741
default_node.op_type = IS_UNUSED;
57405742
op_array->required_num_args = i + 1;
5743+
if (have_optional_param) {
5744+
zend_error(E_COMPILE_WARNING, "Required parameter $%s follows optional parameter",
5745+
ZSTR_VAL(name));
5746+
}
57415747
}
57425748

57435749
arg_info = &arg_infos[i];

ext/reflection/tests/ReflectionClass_isArray.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public bool ReflectionParameter::isArray ( void );
44
marcosptf - <[email protected]> - @phpsp - sao paulo - br
55
--FILE--
66
<?php
7-
function testReflectionIsArray($a = null, $b = 0, array $c, $d=true, array $e, $f=1.5, $g="", array $h, $i="#F989898") {}
7+
8+
function testReflectionIsArray(array $a, ?array $b, iterable $c, array|string $d) {}
89

910
$reflection = new ReflectionFunction('testReflectionIsArray');
1011

@@ -13,12 +14,7 @@ foreach ($reflection->getParameters() as $parameter) {
1314
}
1415
?>
1516
--EXPECT--
16-
bool(false)
17-
bool(false)
1817
bool(true)
19-
bool(false)
2018
bool(true)
2119
bool(false)
2220
bool(false)
23-
bool(true)
24-
bool(false)

ext/reflection/tests/ReflectionType_001.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ReflectionParameter::get/hasType and ReflectionType tests
33
--FILE--
44
<?php
5-
function foo(stdClass $a, array $b, callable $c, stdClass $d = null, $e = null, string $f, bool $g, int $h, float $i, NotExisting $j) { }
5+
function foo(stdClass $a, array $b, callable $c, string $f, bool $g, int $h, float $i, NotExisting $j, stdClass $d = null, $e = null) { }
66

77
function bar(): stdClass { return new stdClass; }
88

@@ -120,36 +120,36 @@ bool(true)
120120
string(8) "callable"
121121
** Function 0 - Parameter 3
122122
bool(true)
123-
bool(true)
124-
bool(false)
125-
string(8) "stdClass"
126-
** Function 0 - Parameter 4
127-
bool(false)
128-
** Function 0 - Parameter 5
129-
bool(true)
130123
bool(false)
131124
bool(true)
132125
string(6) "string"
133-
** Function 0 - Parameter 6
126+
** Function 0 - Parameter 4
134127
bool(true)
135128
bool(false)
136129
bool(true)
137130
string(4) "bool"
138-
** Function 0 - Parameter 7
131+
** Function 0 - Parameter 5
139132
bool(true)
140133
bool(false)
141134
bool(true)
142135
string(3) "int"
143-
** Function 0 - Parameter 8
136+
** Function 0 - Parameter 6
144137
bool(true)
145138
bool(false)
146139
bool(true)
147140
string(5) "float"
148-
** Function 0 - Parameter 9
141+
** Function 0 - Parameter 7
149142
bool(true)
150143
bool(false)
151144
bool(false)
152145
string(11) "NotExisting"
146+
** Function 0 - Parameter 8
147+
bool(true)
148+
bool(true)
149+
bool(false)
150+
string(8) "stdClass"
151+
** Function 0 - Parameter 9
152+
bool(false)
153153
** Function 1 - Parameter 0
154154
bool(true)
155155
bool(false)

ext/reflection/tests/bug62715.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ foreach ($r->getParameters() as $p) {
1616
}
1717
}
1818
?>
19-
--EXPECT--
19+
--EXPECTF--
20+
Warning: Required parameter $c follows optional parameter in %s on line %d
2021
bool(true)
2122
bool(true)
2223
bool(false)

0 commit comments

Comments
 (0)