[php-src] Issue #18736: Returning by ref + finally allow circumventing return type checks
| From: | iluuu1994 | Date: | Mon, 02 Jun 2025 10:51:55 +0000 |
| Subject: | [php-src] Issue #18736: Returning by ref + finally allow circumventing return type checks | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250195@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/18736
Author: iluuu1994
### Description
The following code:
https://3v4l.org/BRBW9
```php
<?php
function &test(): int {
$x = 0;
try {
return $x;
} finally {
$x = 'test';
}
}
$x = &test();
var_dump($x);
```
Resulted in this output:
```
string(4) "test"
```
But I expected this output instead:
```
Fatal error: Uncaught TypeError: test(): Return value must be of type int, string returned
```
### PHP Version
```plain
PHP 7.0.2+
```
### Operating System
_No response_