Skip to content

Commit ff039c3

Browse files
committed
Merge commit 'refs/pull/1066/head' of git://github.com/php/php-src
* git://github.com/php/php-src: Add zend assert deleted by accident Let's keep it simple Improve internal function return types checking for parent
2 parents 13eed26 + 49073fc commit ff039c3

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Zend/tests/return_types/026.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Return type of parent is not allowed in function
3+
--FILE--
4+
<?php
5+
6+
function test(): parent {}
7+
8+
--EXPECTF--
9+
Fatal error: Cannot declare a return type of parent outside of a class scope in %s on line 3

Zend/tests/return_types/027.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Return type of parent is not allowed in closure
3+
--FILE--
4+
<?php
5+
6+
$c = function(): parent {};
7+
8+
--EXPECTF--
9+
Fatal error: Cannot declare a return type of parent outside of a class scope in %s on line 3

Zend/zend_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,8 +2007,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
20072007
if (info->type_hint) {
20082008
if (info->class_name) {
20092009
ZEND_ASSERT(info->type_hint == IS_OBJECT);
2010-
if (!strcasecmp(info->class_name, "self") && !scope) {
2011-
zend_error(E_CORE_ERROR, "Cannot declare a return type of self outside of a class scope");
2010+
if (!scope && (!strcasecmp(info->class_name, "self") || !strcasecmp(info->class_name, "parent"))) {
2011+
zend_error(E_CORE_ERROR, "Cannot declare a return type of %s outside of a class scope", info->class_name);
20122012
}
20132013
}
20142014

0 commit comments

Comments
 (0)