Merge branch 'PHP-8.2'

* PHP-8.2:
  Fix GH-9655: Allow pure intersection types to be implicitly nullable
This commit is contained in:
George Peter Banyard 2022-10-03 11:03:31 +01:00
commit 8f63cc7b8b
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
2 changed files with 7 additions and 12 deletions

View File

@ -1,10 +1,14 @@
--TEST--
Intersection types cannot be implicitly nullable
Intersection types can be implicitly nullable
--FILE--
<?php
function foo(X&Y $foo = null) {}
function foo(X&Y $foo = null) {
var_dump($foo);
}
foo(null);
?>
--EXPECTF--
Fatal error: Cannot use null as default value for parameter $foo of type X&Y in %s on line %d
NULL

View File

@ -6820,15 +6820,6 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
zend_error_noreturn(E_COMPILE_ERROR, "never cannot be used as a parameter type");
}
if (force_nullable && ZEND_TYPE_IS_INTERSECTION(arg_info->type)) {
/* We drop the nullable type flag to generate the correct type string */
ZEND_TYPE_FULL_MASK(arg_info->type) = ZEND_TYPE_FULL_MASK(arg_info->type) & ~MAY_BE_NULL;
zend_string *type_str = zend_type_to_string(arg_info->type);
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot use null as default value for parameter $%s of type %s",
ZSTR_VAL(name), ZSTR_VAL(type_str));
}
if (default_type != IS_UNDEF && default_type != IS_CONSTANT_AST && !force_nullable
&& !zend_is_valid_default_value(arg_info->type, &default_node.u.constant)) {
zend_string *type_str = zend_type_to_string(arg_info->type);