Skip to content

Commit 279ffdb

Browse files
HypeMCGirgias
authored andcommitted
Fix GH-9655: Allow pure intersection types to be implicitly nullable
Closes GH-9659
1 parent a5003bb commit 279ffdb

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.0RC4
44

5+
- Core:
6+
. Fixed bug GH-9655 (Pure intersection types cannot be implicitly nullable)
7+
(Girgias)
8+
59
- Streams:
610
. Fixed bug GH-9590 (stream_select does not abort upon exception or empty
711
valid fd set). (Arnaud)
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
@@ -6819,15 +6819,6 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
68196819
zend_error_noreturn(E_COMPILE_ERROR, "never cannot be used as a parameter type");
68206820
}
68216821

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

0 commit comments

Comments
 (0)