Skip to content

Commit

Permalink
Fix bug pointed out in feature request 81268
Browse files Browse the repository at this point in the history
The error message which is generated when one tries to assign null to an intersection type property is wrong and misleading
  • Loading branch information
Girgias committed Jul 17, 2021
1 parent edb6b37 commit 3cfcfac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Zend/tests/type_declarations/intersection_types/bug81268.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Bug #81268 Wrong message when using null as a default value for intersection types
--FILE--
<?php

class Test {
public X&Y $y = null;
}

?>
--EXPECTF--
Fatal error: Cannot use null as default value for property Test::$y of type X&Y in %s on line %d
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -7324,7 +7324,7 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, z
if (ZEND_TYPE_IS_SET(type) && !Z_CONSTANT(value_zv)
&& !zend_is_valid_default_value(type, &value_zv)) {
zend_string *str = zend_type_to_string(type);
if (Z_TYPE(value_zv) == IS_NULL) {
if (Z_TYPE(value_zv) == IS_NULL && !ZEND_TYPE_IS_INTERSECTION(type)) {
ZEND_TYPE_FULL_MASK(type) |= MAY_BE_NULL;
zend_string *nullable_str = zend_type_to_string(type);

Expand Down

0 comments on commit 3cfcfac

Please sign in to comment.