Skip to content

fix GH-20469: inheritance cache lookup with nested autoloading #22221

Open
morrisonlevi wants to merge 1 commit into
php:PHP-8.4from
morrisonlevi:crash-instanceof_function_slow
Open

fix GH-20469: inheritance cache lookup with nested autoloading #22221
morrisonlevi wants to merge 1 commit into
php:PHP-8.4from
morrisonlevi:crash-instanceof_function_slow

Conversation

@morrisonlevi
Copy link
Copy Markdown
Contributor

@morrisonlevi morrisonlevi commented Jun 3, 2026

Crashes commonly manifest in instanceof_function_slow. unlinked_instanceof() may see a linked starting class while an ancestor in its parent chain is still unlinked. Keep the guarded traversal instead of delegating to instanceof_function(), which assumes resolved parent pointers throughout the chain.

See the ext/opcache/tests/gh20469.phpt test I added.

This has been a bug since PHP 8.1, I can reproduce it with the dockerhub php:8.1-cli image. I'm targeting PHP 8.4 for the fix, as it's the oldest version in active support.

unlinked_instanceof() may see a linked starting class while an
ancestor in its parent chain is still unlinked. Keep the guarded
traversal instead of delegating to instanceof_function(), which assumes
resolved parent pointers throughout the chain.

See ext/opcache/tests/gh20469.phpt.
@arnaud-lb
Copy link
Copy Markdown
Member

There may be a deeper issue as I think that we are supposed to mark classes as linked only when the fully hierarchy is linked. Especially, we shouldn't cache such class in the inheritance cache.

We can observe that linking is not complete as methods from grand parent of ChildOfParentBeingLinked are not inherited:

diff --git a/ext/opcache/tests/gh20469.phpt b/ext/opcache/tests/gh20469.phpt
index 1cd826c177e..dfab60c79be 100644
--- a/ext/opcache/tests/gh20469.phpt
+++ b/ext/opcache/tests/gh20469.phpt
@@ -33,6 +33,9 @@
 <?php
 require __DIR__ . '/autoload.php';
 echo \APP\ParentBeingLinked::SOME_CONSTANT;
+$i = new \APP\ChildOfParentBeingLinked();
+var_dump($i->test());
 PHP);
 
 file_put_contents($dir . '/classes/RootForTraitReturn.php', <<<'PHP'
@@ -44,6 +47,7 @@ class RootForTraitReturn
     function createResult(): BaseCovariantReturn
     {
     }
+    function test() {}
 }
 PHP);

The call results in

Uncaught Error: Call to undefined method APP\ChildOfParentBeingLinked::test() in ext/opcache/tests/gh20469/test2.php:6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants