[php-src] Issue #9407: Eval'd code with static return type wrongly overriden do not show correct message
| From: | shavounet | Date: | Tue, 23 Aug 2022 15:22:12 +0000 |
| Subject: | [php-src] Issue #9407: Eval'd code with static return type wrongly overriden do not show correct message | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242295@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9407
Author: shavounet
### Description
This might be only an issue in the error message since I didn't find any issue with a valid
eval'd code.
It's quite minor, but I did loose some time trying to understand it :)
The following code:
```php
<?php
class Request {
public function duplicate(): static
{
return new Request;
}
}
class TestGenerator {
public static function generate(): void
{
$code = <<<PHP
class MockRequest extends Request {
public function duplicate(): Request
{
return new MockRequest;
}
}
PHP;
eval($code);
}
}
TestGenerator::generate();
$b = new MockRequest;
$b->duplicate();
```
Resulted in this output:
```
PHP Fatal error: Declaration of MockRequest::duplicate(): Request must be compatible with
Request::duplicate(): TestGenerator in var/test.php(20) : eval()'d code on line 2
```
But I expected this output instead:
```
PHP Fatal error: Declaration of MockRequest::duplicate(): Request must be compatible with
Request::duplicate(): static in var/test.php(20) : eval()'d code on line 2
```
With a correct eval'd code (
static return type), I do not have issues.
With a bad not-eval'd code, I do have a correct error message.
I can reproduce it with self and parent return types.
### PHP Version
PHP 8.1.9
### Operating System
_No response_