Skip to content

Commit b67eb34

Browse files
pmmagakrakjoe
authored andcommitted
Inheritance checks should not ignore parents if these implement an interface
1 parent bf914ff commit b67eb34

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

Zend/tests/bug62358.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class B extends A {
2323
}
2424
?>
2525
--EXPECTF--
26-
Fatal error: Declaration of B::foo($var) must be compatible with I::foo() in %sbug62358.php on line 17
26+
Fatal error: Declaration of B::foo($var) must be compatible with A::foo() in %sbug62358.php on line 17

Zend/tests/bug73987.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #73987 (Method compatibility check looks to original definition and not parent)
3+
--FILE--
4+
<?php
5+
6+
interface I {
7+
public function example($a, $b, $c);
8+
}
9+
class A implements I {
10+
public function example($a, $b = null, $c = null) { } // compatible with I::example
11+
}
12+
class B extends A {
13+
public function example($a, $b, $c = null) { } // compatible with I::example
14+
}
15+
16+
?>
17+
--EXPECTF--
18+
Fatal error: Declaration of B::example($a, $b, $c = NULL) must be compatible with A::example($a, $b = NULL, $c = NULL) in %s

Zend/tests/bug73987_1.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #73987 (Method compatibility check looks to original definition and not parent)
3+
--FILE--
4+
<?php
5+
6+
interface I {
7+
public function example();
8+
}
9+
class A implements I {
10+
public function example(): int { } // compatible with I::example
11+
}
12+
class B extends A {
13+
public function example(): string { } // compatible with I::example
14+
}
15+
16+
?>
17+
--EXPECTF--
18+
Fatal error: Declaration of B::example(): string must be compatible with A::example(): int in %s

Zend/zend_inheritance.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,12 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
607607
} else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
608608
/* ctors only have a prototype if it comes from an interface */
609609
child->common.prototype = parent->common.prototype ? parent->common.prototype : parent;
610+
/* and if that is the case, we want to check inheritance against it */
611+
if (parent->common.fn_flags & ZEND_ACC_CTOR) {
612+
parent = child->common.prototype;
613+
}
610614
}
611615

612-
if (child->common.prototype && (
613-
child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT
614-
)) {
615-
parent = child->common.prototype;
616-
}
617616
if (UNEXPECTED(!zend_do_perform_implementation_check(child, parent))) {
618617
int error_level;
619618
const char *error_verb;

0 commit comments

Comments
 (0)