mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
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.
This commit is contained in:
parent
d1e5006c14
commit
0585548106
3 changed files with 23 additions and 5 deletions
|
@ -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
|
||||
|
|
18
Zend/tests/constructor_abstract_grantparent.phpt
Normal file
18
Zend/tests/constructor_abstract_grantparent.phpt
Normal file
|
@ -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
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue