Merge branch 'PHP-8.1' into PHP-8.2

* PHP-8.1:
  Fix lsp error in eval'd code referring to incorrect class for static type
This commit is contained in:
Ilija Tovilo 2022-09-08 10:54:02 +02:00
commit 580c29e1a2
No known key found for this signature in database
GPG Key ID: A4F5D403F118200A
2 changed files with 26 additions and 1 deletions

24
Zend/tests/gh9407.phpt Normal file
View File

@ -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

View File

@ -1259,7 +1259,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;