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 15ee9d2

Browse files
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix lsp error in eval'd code referring to incorrect class for static type
2 parents a795f3e + d5373ea commit 15ee9d2

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
@@ -1227,7 +1227,8 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
12271227
}
12281228
if (type_mask & MAY_BE_STATIC) {
12291229
zend_string *name = ZSTR_KNOWN(ZEND_STR_STATIC);
1230-
if (scope) {
1230+
// During compilation of eval'd code the called scope refers to the scope calling the eval
1231+
if (scope && !zend_is_compiling()) {
12311232
zend_class_entry *called_scope = zend_get_called_scope(EG(current_execute_data));
12321233
if (called_scope) {
12331234
name = called_scope->name;

0 commit comments

Comments
(0)

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