Skip to content

Commit b63436a

Browse files
committed
Don't throw deprecation for poor-mans nullable types
1 parent 509482a commit b63436a

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

Zend/tests/bug71428.3.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ 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-
Deprecated: Required parameter $n follows optional parameter in %s on line %d
11-
1210
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var_dump(call_user_func(array('foo', 'teste')));
1818

1919
?>
2020
--EXPECTF--
21-
Deprecated: Required parameter $b follows optional parameter in %s on line %d
21+
Deprecated: Required parameter $b follows optional parameter $a in %s on line %d
2222
string(1) "x"
2323
array(1) {
2424
[0]=>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Required parameter after optional is deprecated
3+
--FILE--
4+
<?php
5+
6+
function test($testA = null, $testB = null, $testC) {}
7+
function test2(Type $test2A = null, $test2B = null, $test2C) {}
8+
function test3(Type $test3A = null, Type2 $test3B = null, $test3C) {}
9+
10+
?>
11+
--EXPECTF--
12+
Deprecated: Required parameter $testC follows optional parameter $testA in %s on line %d
13+
14+
Deprecated: Required parameter $test2C follows optional parameter $test2B in %s on line %d

Zend/zend_compile.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,7 +5679,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
56795679
uint32_t i;
56805680
zend_op_array *op_array = CG(active_op_array);
56815681
zend_arg_info *arg_infos;
5682-
zend_bool have_optional_param = 0;
5682+
zend_string *optional_param = NULL;
56835683

56845684
if (return_type_ast) {
56855685
/* Use op_array->arg_info[-1] for return type */
@@ -5748,14 +5748,23 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
57485748
default_node.op_type = IS_CONST;
57495749
zend_const_expr_to_zval(&default_node.u.constant, default_ast);
57505750
CG(compiler_options) = cops;
5751-
have_optional_param = 1;
5751+
5752+
if (!optional_param) {
5753+
/* Ignore parameters of the form "Type $param = null".
5754+
* This is the PHP 5 style way of writing "?Type $param", so allow it for now. */
5755+
zend_bool is_implicit_nullable =
5756+
type_ast && Z_TYPE(default_node.u.constant) == IS_NULL;
5757+
if (!is_implicit_nullable) {
5758+
optional_param = name;
5759+
}
5760+
}
57525761
} else {
57535762
opcode = ZEND_RECV;
57545763
default_node.op_type = IS_UNUSED;
57555764
op_array->required_num_args = i + 1;
5756-
if (have_optional_param) {
5757-
zend_error(E_DEPRECATED, "Required parameter $%s follows optional parameter",
5758-
ZSTR_VAL(name));
5765+
if (optional_param) {
5766+
zend_error(E_DEPRECATED, "Required parameter $%s follows optional parameter $%s",
5767+
ZSTR_VAL(name), ZSTR_VAL(optional_param));
57595768
}
57605769
}
57615770

ext/reflection/tests/bug62715.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ foreach ($r->getParameters() as $p) {
1717
}
1818
?>
1919
--EXPECTF--
20-
Deprecated: Required parameter $c follows optional parameter in %s on line %d
20+
Deprecated: Required parameter $c follows optional parameter $b in %s on line %d
2121
bool(true)
2222
bool(true)
2323
bool(false)

0 commit comments

Comments
 (0)