]> granicus.if.org Git - php/commitdiff
Inheritance checks should not ignore parents if these implement an interface
authorPedro Magalhães <mail@pmmaga.net>
Thu, 26 Jan 2017 22:50:56 +0000 (23:50 +0100)
committerJoe Watkins <krakjoe@php.net>
Sat, 28 Jan 2017 06:28:10 +0000 (06:28 +0000)
Zend/tests/bug62358.phpt
Zend/tests/bug73987.phpt [new file with mode: 0644]
Zend/tests/bug73987_1.phpt [new file with mode: 0644]
Zend/zend_inheritance.c

index 35bbc33835b0d557f90ed78e57f2c1c2c51638f5..8509383d469486d57b816ba4e582d91020a377d3 100644 (file)
@@ -23,4 +23,4 @@ class B extends A {
 }
 ?>
 --EXPECTF--
-Fatal error: Declaration of B::foo($var) must be compatible with I::foo() in %sbug62358.php on line 17
+Fatal error: Declaration of B::foo($var) must be compatible with A::foo() in %sbug62358.php on line 17
diff --git a/Zend/tests/bug73987.phpt b/Zend/tests/bug73987.phpt
new file mode 100644 (file)
index 0000000..5515656
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #73987 (Method compatibility check looks to original definition and not parent)
+--FILE--
+<?php
+
+interface I {
+  public function example($a, $b, $c);
+}
+class A implements I {
+  public function example($a, $b = null, $c = null) { } // compatible with I::example
+}
+class B extends A {
+  public function example($a, $b, $c = null) { } // compatible with I::example
+}
+
+?>
+--EXPECTF--
+Fatal error: Declaration of B::example($a, $b, $c = NULL) must be compatible with A::example($a, $b = NULL, $c = NULL) in %s
diff --git a/Zend/tests/bug73987_1.phpt b/Zend/tests/bug73987_1.phpt
new file mode 100644 (file)
index 0000000..6a0a157
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #73987 (Method compatibility check looks to original definition and not parent)
+--FILE--
+<?php
+
+interface I {
+  public function example();
+}
+class A implements I {
+  public function example(): int { } // compatible with I::example
+}
+class B extends A {
+  public function example(): string { } // compatible with I::example
+}
+
+?>
+--EXPECTF--
+Fatal error: Declaration of B::example(): string must be compatible with A::example(): int in %s
index fd1345f844fa554e7db5f565ca0a34d60ba00efb..8ad5cc2e01b23879c419d8a765eefa74d4fd4a9c 100644 (file)
@@ -607,13 +607,12 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
        } else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
                /* ctors only have a prototype if it comes from an interface */
                child->common.prototype = parent->common.prototype ? parent->common.prototype : parent;
+               /* and if that is the case, we want to check inheritance against it */
+               if (parent->common.fn_flags & ZEND_ACC_CTOR) {
+                       parent = child->common.prototype;
+               }
        }
 
-       if (child->common.prototype && (
-               child->common.prototype->common.fn_flags & ZEND_ACC_ABSTRACT
-       )) {
-               parent = child->common.prototype;
-       }
        if (UNEXPECTED(!zend_do_perform_implementation_check(child, parent))) {
                int error_level;
                const char *error_verb;