summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReeze Xia <reeze@php.net>2015-02-07 14:19:56 +0800
committerReeze Xia <reeze@php.net>2015-02-07 14:19:56 +0800
commitd9c28c558172281f78b47846357e1f48154d6a32 (patch)
treeb0ff5eca2c99744e3815af2d070033d196f26d44
parente82e22e27bd81027ea3a92ab6a34f31727049b1e (diff)
downloadphp-git-d9c28c558172281f78b47846357e1f48154d6a32.tar.gz
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.
-rw-r--r--Zend/tests/return_types/026.phpt9
-rw-r--r--Zend/tests/return_types/027.phpt9
-rw-r--r--Zend/zend_API.c12
3 files changed, 28 insertions, 2 deletions
diff --git a/Zend/tests/return_types/026.phpt b/Zend/tests/return_types/026.phpt
new file mode 100644
index 0000000000..44ae82a356
--- /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 0000000000..4d615b4bf6
--- /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 69327778e3..260b0628b3 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);
}
}