From: Pedro Magalhães Date: Thu, 26 Jan 2017 22:50:56 +0000 (+0100) Subject: Inheritance checks should not ignore parents if these implement an interface X-Git-Tag: php-7.1.2RC1~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b67eb3440bb244adf6957bf2c68aeeaa6efc8c8d;p=php Inheritance checks should not ignore parents if these implement an interface --- diff --git a/Zend/tests/bug62358.phpt b/Zend/tests/bug62358.phpt index 35bbc33835..8509383d46 100644 --- a/Zend/tests/bug62358.phpt +++ b/Zend/tests/bug62358.phpt @@ -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 index 0000000000..551565650c --- /dev/null +++ b/Zend/tests/bug73987.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #73987 (Method compatibility check looks to original definition and not parent) +--FILE-- + +--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 index 0000000000..6a0a157f29 --- /dev/null +++ b/Zend/tests/bug73987_1.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #73987 (Method compatibility check looks to original definition and not parent) +--FILE-- + +--EXPECTF-- +Fatal error: Declaration of B::example(): string must be compatible with A::example(): int in %s diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index fd1345f844..8ad5cc2e01 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -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;