Skip to content

Returning by ref + finally allow circumventing return type checks #18736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iluuu1994 opened this issue Jun 2, 2025 · 1 comment
Open

Returning by ref + finally allow circumventing return type checks #18736

iluuu1994 opened this issue Jun 2, 2025 · 1 comment

Comments

@iluuu1994
Copy link
Member

Description

The following code:

https://3v4l.org/BRBW9

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

PHP 7.0.2+

Operating System

No response

@DanielEScherzer
Copy link
Member

Naive guess that this might be from 778e5f3, which moved the finally handling to after the return type check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants