Skip to content

Commit

Permalink
Partially address bug #78647
Browse files Browse the repository at this point in the history
Produce a sensible error message for the case where inheritance
should fail. There is still a remaining issue that we sometimes
fail inheritance while we should not.
  • Loading branch information
nikic committed Nov 5, 2021
1 parent c19c380 commit a2fe8d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Bug #78647: Outstanding dependency obligation
--FILE--
<?php

spl_autoload_register(function ($class) {
if ($class == 'A') {
class A {
function m(): B {}
}
} elseif ($class == 'B') {
class B extends A {
function m(): X {}
}
} else {
class C extends B {}
}
});

new B;

?>
--EXPECTF--
Fatal error: Could not check compatibility between B::m(): X and A::m(): B, because class X is not available in %s on line %d
3 changes: 2 additions & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,8 @@ static void report_variance_errors(zend_class_entry *ce) {
} else if (obligation->type == OBLIGATION_PROPERTY_COMPATIBILITY) {
emit_incompatible_property_error(obligation->child_prop, obligation->parent_prop);
} else {
zend_error_noreturn(E_CORE_ERROR, "Bug #78647");
/* Report variance errors of the dependency, which prevent it from being linked. */
report_variance_errors(obligation->dependency_ce);
}
} ZEND_HASH_FOREACH_END();

Expand Down

0 comments on commit a2fe8d4

Please sign in to comment.