Skip to content

Commit 8f63cc7

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-9655: Allow pure intersection types to be implicitly nullable
2 parents 31aeed2 + 279ffdb commit 8f63cc7

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
--TEST--
2-
Intersection types cannot be implicitly nullable
2+
Intersection types can be implicitly nullable
33
--FILE--
44
<?php
55

6-
function foo(X&Y $foo = null) {}
6+
function foo(X&Y $foo = null) {
7+
var_dump($foo);
8+
}
9+
10+
foo(null);
711

812
?>
913
--EXPECTF--
10-
Fatal error: Cannot use null as default value for parameter $foo of type X&Y in %s on line %d
14+
NULL

Zend/zend_compile.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,15 +6820,6 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
68206820
zend_error_noreturn(E_COMPILE_ERROR, "never cannot be used as a parameter type");
68216821
}
68226822

6823-
if (force_nullable && ZEND_TYPE_IS_INTERSECTION(arg_info->type)) {
6824-
/* We drop the nullable type flag to generate the correct type string */
6825-
ZEND_TYPE_FULL_MASK(arg_info->type) = ZEND_TYPE_FULL_MASK(arg_info->type) & ~MAY_BE_NULL;
6826-
zend_string *type_str = zend_type_to_string(arg_info->type);
6827-
zend_error_noreturn(E_COMPILE_ERROR,
6828-
"Cannot use null as default value for parameter $%s of type %s",
6829-
ZSTR_VAL(name), ZSTR_VAL(type_str));
6830-
}
6831-
68326823
if (default_type != IS_UNDEF && default_type != IS_CONSTANT_AST && !force_nullable
68336824
&& !zend_is_valid_default_value(arg_info->type, &default_node.u.constant)) {
68346825
zend_string *type_str = zend_type_to_string(arg_info->type);

0 commit comments

Comments
 (0)