From 0220a8318cf62b52962d03deef7aeb94332e4f43 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 15 Nov 2005 16:50:07 +0000 Subject: [PATCH] Allow "null" default value for arguments with array type hint Unicode support --- Zend/zend.h | 1 + Zend/zend_compile.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Zend/zend.h b/Zend/zend.h index de932d8c5e..46983a2354 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -684,6 +684,7 @@ END_EXTERN_C() (!memcmp((ustr),(str),(slen))): \ (!zend_cmp_unicode_and_literal(((UChar*)(ustr)), ulen, str, slen))) + #endif /* ZEND_H */ /* diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 66082ba84b..f1fbbba2dc 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1301,6 +1301,19 @@ void zend_do_end_function_declaration(znode *function_token TSRMLS_DC) } +static inline int ZEND_U_CASE_EQUAL(zend_uchar type, void *ustr, int ulen, char *str, int slen) +{ + void* lcname; + unsigned int lcname_len; + int ret; + + lcname = zend_u_str_case_fold(type, ustr, ulen, 0, &lcname_len); + ret = ZEND_U_EQUAL(type, lcname, lcname_len, str, slen); + efree(lcname); + return ret; +} + + void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initialization, znode *class_type, znode *varname, zend_uchar pass_by_reference TSRMLS_DC) { zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); @@ -1329,13 +1342,15 @@ void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initia cur_arg_info->pass_by_reference = pass_by_reference; if (class_type->op_type != IS_UNUSED) { + cur_arg_info->allow_null = 0; if (class_type->u.constant.type == IS_STRING || class_type->u.constant.type == IS_UNICODE) { cur_arg_info->class_name = Z_UNIVAL(class_type->u.constant); cur_arg_info->class_name_len = Z_UNILEN(class_type->u.constant); - - /* FIXME: make this work for unicode=on too */ if (op == ZEND_RECV_INIT) { - if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) { + if (Z_TYPE(initialization->u.constant) == IS_NULL || + (Z_TYPE(initialization->u.constant) == IS_CONSTANT && + Z_UNILEN(initialization->u.constant) == sizeof("null") - 1 && + ZEND_U_CASE_EQUAL(UG(unicode)?IS_UNICODE:IS_STRING, Z_UNIVAL(initialization->u.constant), Z_UNILEN(initialization->u.constant), "null", sizeof("null")-1))) { cur_arg_info->allow_null = 1; } else { zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only be NULL"); @@ -1345,6 +1360,16 @@ void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initia cur_arg_info->array_type_hint = 1; cur_arg_info->class_name = NULL; cur_arg_info->class_name_len = 0; + if (op == ZEND_RECV_INIT) { + if (Z_TYPE(initialization->u.constant) == IS_NULL || + (Z_TYPE(initialization->u.constant) == IS_CONSTANT && + Z_UNILEN(initialization->u.constant) == sizeof("null") - 1 && + ZEND_U_CASE_EQUAL(UG(unicode)?IS_UNICODE:IS_STRING, Z_UNIVAL(initialization->u.constant), Z_UNILEN(initialization->u.constant), "null", sizeof("null")-1))) { + cur_arg_info->allow_null = 1; + } else if (Z_TYPE(initialization->u.constant) != IS_ARRAY && Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) { + zend_error(E_COMPILE_ERROR, "Default value for parameters with array type hint can only be an array or NULL"); + } + } } } else { cur_arg_info->class_name = NULL; -- 2.40.0