From 727c62e3fa412c687f8ad4908f40f1413bda85d9 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Tue, 18 Sep 2018 15:11:01 +0200 Subject: [PATCH] Deprecate implicit nullable parameters --- Zend/zend_compile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 2050e3ba71151..48866723c5e85 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5829,7 +5829,8 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall if (type_ast) { uint32_t default_type = default_ast ? Z_TYPE(default_node.u.constant) : IS_UNDEF; - + zend_bool is_arg_explicitly_nullable = (type_ast->attr & ZEND_TYPE_NULLABLE) == ZEND_TYPE_NULLABLE; + op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS; arg_info->type = zend_compile_typename( type_ast, default_type == IS_NULL, /* use_arena */ 0); @@ -5838,6 +5839,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type"); } + + if (default_type == IS_NULL && !is_arg_explicitly_nullable) { + zend_error(E_DEPRECATED, "Implicit nullable types are deprecated, mark the type as explicitly nullable with the '?' sign"); + } + + if (default_type > IS_NULL && default_type != IS_CONSTANT_AST && !zend_is_valid_default_value(arg_info->type, &default_node.u.constant)) { zend_string *type_str = zend_type_to_string(arg_info->type);