Skip to content

Commit d5373ea

Browse files
committed
Fix lsp error in eval'd code referring to incorrect class for static type
Fixes GH-9407 Closes GH-9471
1 parent 1435fc6 commit d5373ea

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
(Tim Starling)
88
. Fixed bug GH-9361 (Segmentation fault on script exit #9379). (cmb,
99
Christian Schneider)
10+
. Fixed bug GH-9407 (LSP error in eval'd code refers to wrong class for static
11+
type). (ilutov)
1012

1113
- DOM:
1214
. Fixed bug #79451 (DOMDocument->replaceChild on doctype causes double free).

Zend/tests/gh9407.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-9407: LSP error in eval'd code refers to wrong class for static type
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function duplicate(): static {}
8+
}
9+
10+
class C {
11+
public static function generate() {
12+
eval(<<<PHP
13+
class B extends A {
14+
public function duplicate(): A {}
15+
}
16+
PHP);
17+
}
18+
}
19+
20+
C::generate();
21+
22+
?>
23+
--EXPECTF--
24+
Fatal error: Declaration of B::duplicate(): A must be compatible with A::duplicate(): static in %s : eval()'d code on line %d

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
12071207
}
12081208
if (type_mask & MAY_BE_STATIC) {
12091209
zend_string *name = ZSTR_KNOWN(ZEND_STR_STATIC);
1210-
if (scope) {
1210+
// During compilation of eval'd code the called scope refers to the scope calling the eval
1211+
if (scope && !zend_is_compiling()) {
12111212
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
12121213
if (called_scope) {
12131214
name = called_scope->name;

0 commit comments

Comments
 (0)