com php-src: Treat abstract ctors the same, regardless of origin: Zend/tests/bug61970_2.phpt Zend/tests/constru ctor_abstract_grantparent.phpt
Zend/zend_inheritance .c
| From: | Nikita Popov | Date: | Wed, 27 Mar 2019 17:09:09 +0000 |
| Subject: | com php-src: Treat abstract ctors the same, regardless of origin: Zend/tests/bug61970_2.phpt Zend/tests/constru ctor_abstract_grantparent.phpt Zend/zend_inheritance .c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105370@lists.php.net to get a copy of this message | ||
Commit: 058554810649da431efa3ab851be17b0d2f96fb8
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 27 Mar 2019 18:09:09 +0100
Parents: d1e5006c1487c0df1333564c3fdcc0528e1da394
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=058554810649da431efa3ab851be17b0d2f96fb8
Log:
Treat abstract ctors the same, regardless of origin
Abstract ctor signatures should always be respected by all children,
independently of whether it comes from an interface or an abstract
class. Previously abstract ctor signatures (if they didn't come from
an interface) were only checked to one level of inheritance..
Changed paths:
M Zend/tests/bug61970_2.phpt
A Zend/tests/constructor_abstract_grantparent.phpt
M Zend/zend_inheritance.c
Diff:
diff --git a/Zend/tests/bug61970_2.phpt b/Zend/tests/bug61970_2.phpt
index 3e4b522..403ba75 100644
--- a/Zend/tests/bug61970_2.phpt
+++ b/Zend/tests/bug61970_2.phpt
@@ -15,4 +15,4 @@ class Baz extends Bar {
protected function __construct(){}
}
--EXPECTF--
-Fatal error: Access level to Baz::__construct() must be public (as in class Bar) in %s on line 12
+Fatal error: Access level to Baz::__construct() must be public (as in class Foo) in %s on line 12
diff --git a/Zend/tests/constructor_abstract_grantparent.phpt
b/Zend/tests/constructor_abstract_grantparent.phpt
new file mode 100644
index 0000000..b813c4c
--- /dev/null
+++ b/Zend/tests/constructor_abstract_grantparent.phpt
@@ -0,0 +1,18 @@
+--TEST--
+LSP checks are performed against an abstract constructor even if it is not a direct parent
+--FILE--
+<?php
+
+abstract class A {
+ abstract function __construct(X $x);
+}
+class B extends A {
+ function __construct(X $x) {}
+}
+class C extends B {
+ function __construct() {}
+}
+
+?>
+--EXPECTF--
+Fatal error: Declaration of C::__construct() must be compatible with A::__construct(X $x) in %s on
line 10
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 72bc9cf..0916d91 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -597,11 +597,11 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function
*
proto = parent;
}
} else if (proto) {
- if (proto->common.scope->ce_flags & ZEND_ACC_INTERFACE) {
- /* ctors only have a prototype if it comes from an interface */
- /* and if that is the case, we want to check inheritance against it */
+ /* ctors only have a prototype if is abstract (or comes from an interface) */
+ /* and if that is the case, we want to check inheritance against it */
+ if (proto->common.fn_flags & ZEND_ACC_ABSTRACT) {
parent = proto;
- } else if (!(proto->common.fn_flags & ZEND_ACC_ABSTRACT)) {
+ } else {
break;
}
} else {