com php-src: Allow adding return type during inheritance: Zend/tests/typehints/add_return_type.phpt Zend/zend_i nheritance.c

From: Date: Sun, 22 Mar 2015 17:56:14 +0000
Subject: com php-src: Allow adding return type during inheritance: Zend/tests/typehints/add_return_type.phpt Zend/zend_i nheritance.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85764@lists.php.net to get a copy of this message
Commit: a34f81deee53ddf3b59405fc37d9f92cf41c8636 Author: Nikita Popov <nikic@php.net> Sun, 22 Mar 2015 18:50:36 +0100 Parents: a50e9d87f265f911f9c76ca0e998588be0bd6eac Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a34f81deee53ddf3b59405fc37d9f92cf41c8636 Log: Allow adding return type during inheritance This is allowed as per the return types RFC. The test for this behavior happened to use an internal class without arginfo, which is why this was not properly implemented. Changed paths: A Zend/tests/typehints/add_return_type.phpt M Zend/zend_inheritance.c Diff: diff --git a/Zend/tests/typehints/add_return_type.phpt b/Zend/tests/typehints/add_return_type.phpt new file mode 100644 index 0000000..de8a17d --- /dev/null +++ b/Zend/tests/typehints/add_return_type.phpt @@ -0,0 +1,23 @@ +--TEST-- +Adding a return type during inheritance is allowed +--FILE-- +<?php + +interface One { + public function a(); + public function b(); + public function c(); + public function d(); +} + +interface Two extends One { + public function a() : stdClass; + public function c() : callable; + public function b() : array; + public function d() : int; +} + +?> +Done +--EXPECT-- +Done diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index e3ef17c..3e9083c 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -328,11 +328,14 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c } } - /* check return type compataibility */ - if ((proto->common.fn_flags | fe->common.fn_flags) & ZEND_ACC_HAS_RETURN_TYPE) { - if ((proto->common.fn_flags ^ fe->common.fn_flags) & ZEND_ACC_HAS_RETURN_TYPE) { + /* Check return type compatibility, but only if the prototype already specifies + * a return type. Adding a new return type is always valid. */ + if (proto->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { + /* Removing a return type is not valid. */ + if (!(fe->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) { return 0; } + if (!zend_do_perform_type_hint_check(fe, fe->common.arg_info - 1, proto, proto->common.arg_info - 1)) { return 0; }

« previous php.cvs (#85764) next »