Fixed variance check for abstract constructor during erlay binding

This commit is contained in:
Dmitry Stogov 2019-06-25 17:43:46 +03:00
parent ccbc121cb1
commit f09d41ffc0
2 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,18 @@
--TEST--
Variance check for abstract constructor
--FILE--
<?php
class X {
}
abstract class A {
abstract function __construct(X $x);
}
class B extends A {
function __construct(object $x) {}
}
class C extends B {
function __construct(Y $x) {}
}
?>
--EXPECTF--
Fatal error: Could not check compatibility between C::__construct(Y $x) and A::__construct(X $x), because class Y is not available in %s on line %d

View File

@ -2395,9 +2395,19 @@ zend_bool zend_can_early_bind(zend_class_entry *ce, zend_class_entry *parent_ce)
zval *zv;
zend_string *unresolved_class;
if ((parent_flags & ZEND_ACC_PRIVATE) ||
((parent_flags & ZEND_ACC_CTOR) && !(parent_flags & ZEND_ACC_ABSTRACT))) {
if (parent_flags & ZEND_ACC_PRIVATE) {
continue;
} else if (parent_flags & ZEND_ACC_CTOR) {
zend_function *proto = parent_func->common.prototype ?
parent_func->common.prototype : parent_func;
/* 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_func = proto;
} else {
continue;
}
}
zv = zend_hash_find_ex(&ce->function_table, key, 1);