com php-src: Allow overriding abstract methods: NEWS UPGRADING Zend/tests/abstract_inheritance_001.phpt Zend/tes ts/abstract_inheritance_002.phpt Zend/tests/abstr act_inheritance_003.phpt Zend/zend_inheritance .c
[email protected] (Nikita Popov)
| Newsgroups | php.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: a5eb57c96e8e851793d419cd4a4b4815a2cb44cb Author: Pedro Magalhães <[email protected]> Sat, 22 Apr 2017 18:41:54 +0200 Committer: Nikita Popov <[email protected]> Wed, 24 May 2017 17:42:01 +0200 Parents: 5dc43b4c9d7dbff583b5906a6d50890d615568c1 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a5eb57c96e8e851793d419cd4a4b4815a2cb44cb Log: Allow overriding abstract methods RFC: https://wiki.php.net/rfc/allow-abstract-function-override Changed paths: M NEWS M UPGRADING A Zend/tests/abstract_inheritance_001.phpt A Zend/tests/abstract_inheritance_002.phpt A Zend/tests/abstract_inheritance_003.phpt M Zend/zend_inheritance.c Diff: diff --git a/NEWS b/NEWS index 8cce767..c231f50 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,8 @@ PHP NEWS loosely-equal value). (pmmaga) . Fixed bug #61970 (Restraining __construct() access level in subclass gives a fatal error). (pmmaga) + . Fixed bug #63384 (Cannot override an abstract method with an abstract + method). (pmmaga, wes) - BCMath: . Fixed bug #46564 (bcmod truncates fractionals). (liborm85) diff --git a/UPGRADING b/UPGRADING index 0530958..4a61694 100644 --- a/UPGRADING +++ b/UPGRADING @@ -101,6 +101,9 @@ PHP 7.2 UPGRADE NOTES inherited method. This complies with contravariance of method argument types under the Liskov Substitution Principle. (https://wiki.php.net/rfc/parameter-no-type-variance) + . It is now allowed to override an abstract method with another abstract + method in a child class. + (https://wiki.php.net/rfc/allow-abstract-function-override) . A trailing comma in group use statements is now allowed. (https://wiki.php.net/rfc/list-syntax-trailing-commas) diff --git a/Zend/tests/abstract_inheritance_001.phpt b/Zend/tests/abstract_inheritance_001.phpt new file mode 100644 index 0000000..9e061e6 --- /dev/null +++ b/Zend/tests/abstract_inheritance_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +Allow abstract function override +--FILE-- +<?php + +abstract class A { abstract function bar($x); } +abstract class B extends A { abstract function bar($x); } + +echo "DONE"; +?> +--EXPECT-- +DONE diff --git a/Zend/tests/abstract_inheritance_002.phpt b/Zend/tests/abstract_inheritance_002.phpt new file mode 100644 index 0000000..78f53c8 --- /dev/null +++ b/Zend/tests/abstract_inheritance_002.phpt @@ -0,0 +1,12 @@ +--TEST-- +Allow abstract function override +--FILE-- +<?php + +abstract class A { abstract function bar($x); } +abstract class B extends A { abstract function bar($x, $y = 0); } + +echo "DONE"; +?> +--EXPECT-- +DONE diff --git a/Zend/tests/abstract_inheritance_003.phpt b/Zend/tests/abstract_inheritance_003.phpt new file mode 100644 index 0000000..24d5920 --- /dev/null +++ b/Zend/tests/abstract_inheritance_003.phpt @@ -0,0 +1,12 @@ +--TEST-- +Allow abstract function override +--FILE-- +<?php + +abstract class A { abstract function bar($x, $y = 0); } +abstract class B extends A { abstract function bar($x); } + +echo "DONE"; +?> +--EXPECTF-- +Fatal error: Declaration of B::bar($x) must be compatible with A::bar($x, $y = 0) in %s diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 3a32215..8f43d15 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -551,16 +551,6 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function * uint32_t child_flags; uint32_t parent_flags = parent->common.fn_flags; - if ((parent->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0 - && parent->common.fn_flags & ZEND_ACC_ABSTRACT - && parent->common.scope != (child->common.prototype ? child->common.prototype->common.scope : child->common.scope) - && child->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_IMPLEMENTED_ABSTRACT)) { - zend_error_noreturn(E_COMPILE_ERROR, "Can't inherit abstract function %s::%s() (previously declared abstract in %s)", - ZSTR_VAL(parent->common.scope->name), - ZSTR_VAL(child->common.function_name), - child->common.prototype ? ZSTR_VAL(child->common.prototype->common.scope->name) : ZSTR_VAL(child->common.scope->name)); - } - if (UNEXPECTED(parent_flags & ZEND_ACC_FINAL)) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot override final method %s::%s()", ZEND_FN_SCOPE_NAME(parent), ZSTR_VAL(child->common.function_name)); }