diff options
author | Hannes Magnusson <bjori@php.net> | 2011-08-16 10:44:47 +0000 |
---|---|---|
committer | Hannes Magnusson <bjori@php.net> | 2011-08-16 10:44:47 +0000 |
commit | 306c42023e048451c6bb819661b229e95f314231 (patch) | |
tree | 91913f59569990d82546e8495ef4fee8a54e24de /Zend/zend_compile.c | |
parent | 466d5414dfb43074c9bbfddad31bc96e4def336d (diff) | |
download | php-git-306c42023e048451c6bb819661b229e95f314231.tar.gz |
Callable typehint following the rules of is_callable($arg, false);
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r-- | Zend/zend_compile.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 48e7a2f0f9..943c5e4991 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1890,27 +1890,38 @@ void zend_do_receive_arg(zend_uchar op, znode *varname, const znode *offset, con cur_arg_info->allow_null = 0; if (class_type->u.constant.type != IS_NULL) { - cur_arg_info->type_hint = IS_OBJECT; - if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_type->u.constant), Z_STRLEN(class_type->u.constant))) { - zend_resolve_class_name(class_type, opline->extended_value, 1 TSRMLS_CC); - } - class_type->u.constant.value.str.val = zend_new_interned_string(class_type->u.constant.value.str.val, class_type->u.constant.value.str.len + 1, 1 TSRMLS_CC); - cur_arg_info->class_name = class_type->u.constant.value.str.val; - cur_arg_info->class_name_len = class_type->u.constant.value.str.len; - 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"))) { - 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"); + if (class_type->u.constant.type == IS_ARRAY) { + cur_arg_info->type_hint = IS_ARRAY; + 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"))) { + 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->type_hint = IS_ARRAY; - 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"))) { - 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 if (class_type->u.constant.type == IS_CALLABLE) { + cur_arg_info->type_hint = IS_CALLABLE; + 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"))) { + cur_arg_info->allow_null = 1; + } else { + zend_error(E_COMPILE_ERROR, "Default value for parameters with callable type hint can only be NULL"); + } + } + } else { + cur_arg_info->type_hint = IS_OBJECT; + if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_type->u.constant), Z_STRLEN(class_type->u.constant))) { + zend_resolve_class_name(class_type, opline->extended_value, 1 TSRMLS_CC); + } + class_type->u.constant.value.str.val = zend_new_interned_string(class_type->u.constant.value.str.val, class_type->u.constant.value.str.len + 1, 1 TSRMLS_CC); + cur_arg_info->class_name = class_type->u.constant.value.str.val; + cur_arg_info->class_name_len = class_type->u.constant.value.str.len; + 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"))) { + 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"); + } } } } |