com php-src: Improve internal function return types checking for parent: Zend/tests/return_types/026.phpt Zend/tests/return _types/027.phpt
Zend/zend_API.c

From: Date: Sat, 07 Feb 2015 06:19:56 +0000
Subject: com php-src: Improve internal function return types checking for parent: Zend/tests/return_types/026.phpt Zend/tests/return _types/027.phpt
Zend/zend_API.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85206@lists.php.net to get a copy of this message
Commit: d9c28c558172281f78b47846357e1f48154d6a32 Author: Reeze Xia <reeze@php.net> Sat, 7 Feb 2015 14:19:56 +0800 Parents: e82e22e27bd81027ea3a92ab6a34f31727049b1e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d9c28c558172281f78b47846357e1f48154d6a32 Log: Improve internal function return types checking for parent Previously the checking was against 'self', 'parent' need to be checked as user land declearation as well. This also add two missing test cases. Changed paths: A Zend/tests/return_types/026.phpt A Zend/tests/return_types/027.phpt M Zend/zend_API.c Diff: diff --git a/Zend/tests/return_types/026.phpt b/Zend/tests/return_types/026.phpt new file mode 100644 index 0000000..44ae82a --- /dev/null +++ b/Zend/tests/return_types/026.phpt @@ -0,0 +1,9 @@ +--TEST-- +Return type of parent is not allowed in function +--FILE-- +<?php + +function test(): parent {} + +--EXPECTF-- +Fatal error: Cannot declare a return type of parent outside of a class scope in %s on line 3 diff --git a/Zend/tests/return_types/027.phpt b/Zend/tests/return_types/027.phpt new file mode 100644 index 0000000..4d615b4 --- /dev/null +++ b/Zend/tests/return_types/027.phpt @@ -0,0 +1,9 @@ +--TEST-- +Return type of parent is not allowed in closure +--FILE-- +<?php + +$c = function(): parent {}; + +--EXPECTF-- +Fatal error: Cannot declare a return type of parent outside of a class scope in %s on line 3 diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 6932777..260b062 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2003,9 +2003,17 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio } if (info->type_hint) { if (info->class_name) { + uint32_t fetch_type; + zend_string *class_name; + ALLOCA_FLAG(use_heap); + ZEND_ASSERT(info->type_hint == IS_OBJECT); - if (!strcasecmp(info->class_name, "self") && !scope) { - zend_error(E_CORE_ERROR, "Cannot declare a return type of self outside of a class scope"); + STR_ALLOCA_INIT(class_name, info->class_name, strlen(info->class_name), use_heap); + fetch_type = zend_get_class_fetch_type(class_name); + STR_ALLOCA_FREE(class_name, use_heap); + + if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !scope) { + zend_error(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", info->class_name); } }

« previous php.cvs (#85206) next »