Skip to content
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

PHPStan hangs on analysing small function #3686

Closed
phpfui opened this issue Jul 29, 2020 · 7 comments
Closed

PHPStan hangs on analysing small function #3686

phpfui opened this issue Jul 29, 2020 · 7 comments

Comments

@phpfui
Copy link

phpfui commented Jul 29, 2020

Bug report

On PHPStan 0.12.33 under Windows 10, PHP 7.4.6.

PHPStan hangs on processing this file (chopped down from working code, this code does not make sense):

Code snippet that reproduces the problem

function fred($request)
	{
		$keys = '';
		foreach ($request as $index)
			{
			foreach ($index as $field)
				{
				if (isset($keys[$field]))
					{
					$keys[$field] = 0;
					}
				}
			}
	}

Expected output

PHPStan finishes, probably with some errors, but it never returns.

It is the first and only file processed. Level 1. If you change just about anything, it does not hang. This is the smallest snippet of code I could make hang. It was hanging on old production code, so pretty sure the code is valid PHP and works correctly with no errors or warnings reported.

@mergeable
Copy link

mergeable bot commented Jul 29, 2020

This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.

@phpfui
Copy link
Author

phpfui commented Jul 30, 2020

I am unable to see how to save a link to the demo / test page. When I copy and paste the above code into the page, I get this error:

An error occured. Please try again later.

@ondrejmirtes
Copy link
Member

Can confirm this behaviour, will look into it.

@muglug
Copy link
Contributor

muglug commented Jul 31, 2020

Here's a properly-typed version that should pass:

<?php

/**
 * @param int[][] $a
 */
function replaceStringWithZero(array $a) : string {
    $keys = 'agfsdafsafdrew1231414';

    foreach ($a as $b) {
        foreach ($b as $c) {
            if (isset($keys[$c])) {
                $keys[$c] = "0";
            }
        }
    }

    return $keys;
}

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@6d81881

@phpfui
Copy link
Author

phpfui commented Aug 2, 2020

Thank you!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants