Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e17a7ac

Browse files
Merge branch 'PHP-8.2'
* PHP-8.2: Fix lsp error in eval'd code referring to incorrect class for static type
2 parents ecc3fc1 + 580c29e commit e17a7ac

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎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
@@ -1259,7 +1259,8 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
12591259
}
12601260
if (type_mask & MAY_BE_STATIC) {
12611261
zend_string *name = ZSTR_KNOWN(ZEND_STR_STATIC);
1262-
if (scope) {
1262+
// During compilation of eval'd code the called scope refers to the scope calling the eval
1263+
if (scope && !zend_is_compiling()) {
12631264
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
12641265
if (called_scope) {
12651266
name = called_scope->name;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /