Skip to content

Fix lsp error in eval'd code referring to incorrect class for static type #9471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PHP NEWS
(Tim Starling)
. Fixed bug GH-9361 (Segmentation fault on script exit #9379). (cmb,
Christian Schneider)
. Fixed bug GH-9407 (LSP error in eval'd code refers to wrong class for static
type). (ilutov)

- DOM:
. Fixed bug #79451 (DOMDocument->replaceChild on doctype causes double free).
Expand Down
24 changes: 24 additions & 0 deletions Zend/tests/gh9407.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-9407: LSP error in eval'd code refers to wrong class for static type
--FILE--
<?php

class A {
public function duplicate(): static {}
}

class C {
public static function generate() {
eval(<<<PHP
class B extends A {
public function duplicate(): A {}
}
PHP);
}
}

C::generate();

?>
--EXPECTF--
Fatal error: Declaration of B::duplicate(): A must be compatible with A::duplicate(): static in %s : eval()'d code on line %d
3 changes: 2 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,8 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
}
if (type_mask & MAY_BE_STATIC) {
zend_string *name = ZSTR_KNOWN(ZEND_STR_STATIC);
if (scope) {
// During compilation of eval'd code the called scope refers to the scope calling the eval
if (scope && !zend_is_compiling()) {
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
if (called_scope) {
name = called_scope->name;
Expand Down