Skip to content

Commit c827124

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Added tests demonstrating the same effect with abstracts Inheritance checks should not ignore parents if these implement an interface
2 parents 8302a29 + c11b2b8 commit c827124

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-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 - nullability interface)
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 - return types interface)
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/tests/bug73987_2.phpt

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

Zend/tests/bug73987_3.phpt

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

Zend/zend_inheritance.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,12 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
586586
} else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
587587
/* ctors only have a prototype if it comes from an interface */
588588
child->common.prototype = parent->common.prototype ? parent->common.prototype : parent;
589+
/* and if that is the case, we want to check inheritance against it */
590+
if (parent->common.fn_flags & ZEND_ACC_CTOR) {
591+
parent = child->common.prototype;
592+
}
589593
}
590594

591-
if (child->common.prototype && (
592-
child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT
593-
)) {
594-
parent = child->common.prototype;
595-
}
596595
if (UNEXPECTED(!zend_do_perform_implementation_check(child, parent))) {
597596
int error_level;
598597
const char *error_verb;

0 commit comments

Comments
 (0)