diff --git a/NEWS b/NEWS index 81762e523fe64..f552ca1aadebe 100644 --- a/NEWS +++ b/NEWS @@ -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). diff --git a/Zend/tests/gh9407.phpt b/Zend/tests/gh9407.phpt new file mode 100644 index 0000000000000..6712c9ccc9c3f --- /dev/null +++ b/Zend/tests/gh9407.phpt @@ -0,0 +1,24 @@ +--TEST-- +GH-9407: LSP error in eval'd code refers to wrong class for static type +--FILE-- + +--EXPECTF-- +Fatal error: Declaration of B::duplicate(): A must be compatible with A::duplicate(): static in %s : eval()'d code on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index cde1758ffc4e2..2a04c49b55f1d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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;