diff options
-rw-r--r-- | Zend/tests/return_types/026.phpt | 9 | ||||
-rw-r--r-- | Zend/tests/return_types/027.phpt | 9 | ||||
-rw-r--r-- | Zend/zend_API.c | 4 |
3 files changed, 20 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 3a6dbe5058..304632f762 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2007,8 +2007,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio if (info->type_hint) { if (info->class_name) { 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"); + if (!scope && (!strcasecmp(info->class_name, "self") || !strcasecmp(info->class_name, "parent"))) { + zend_error(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", info->class_name); } } |