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
This commit is contained in:
George Peter Banyard 2021-07-17 01:39:29 +02:00
parent edb6b375dd
commit 3cfcfacd36
2 changed files with 13 additions and 1 deletions

View file

@ -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

View file

@ -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);