Skip to content

Commit 3cfcfac

Browse files
committed
Fix bug pointed out in feature request 81268
The error message which is generated when one tries to assign null to an intersection type property is wrong and misleading
1 parent edb6b37 commit 3cfcfac

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #81268 Wrong message when using null as a default value for intersection types
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public X&Y $y = null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Cannot use null as default value for property Test::$y of type X&Y in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7324,7 +7324,7 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, z
73247324
if (ZEND_TYPE_IS_SET(type) && !Z_CONSTANT(value_zv)
73257325
&& !zend_is_valid_default_value(type, &value_zv)) {
73267326
zend_string *str = zend_type_to_string(type);
7327-
if (Z_TYPE(value_zv) == IS_NULL) {
7327+
if (Z_TYPE(value_zv) == IS_NULL && !ZEND_TYPE_IS_INTERSECTION(type)) {
73287328
ZEND_TYPE_FULL_MASK(type) |= MAY_BE_NULL;
73297329
zend_string *nullable_str = zend_type_to_string(type);
73307330

0 commit comments

Comments
 (0)