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

Array destructuring does not trigger undefined index #3267

Closed
iluuu1994 opened this issue May 8, 2020 · 4 comments
Closed

Array destructuring does not trigger undefined index #3267

iluuu1994 opened this issue May 8, 2020 · 4 comments

Comments

@iluuu1994
Copy link
Contributor

iluuu1994 commented May 8, 2020

Feature request

https://phpstan.org/r/7a9008c1-c923-4c04-8bbb-9886b5a40bdc

/**
 * @return array{int, int}
 */
function size(): array
{
    return [10, 20];
}

class HelloWorld {
	public function bar(): void {
		$x = size()[2]; // Offset 2 does not exist on array(int, int).
		[$width, $height, $depth] = size(); // Nothing
	}
}

Interestingly Psalm has the exact same bug missing feature https://psalm.dev/r/c335c7713c :)

@ondrejmirtes
Copy link
Member

Actually it's a feature request, there curently isn't a check for that :) (False positives are bugs, false negatives are feature requests in my eye)

@iluuu1994
Copy link
Contributor Author

Fair enough 🙂

@ondrejmirtes
Copy link
Member

Implemented :) https://phpstan.org/r/20b36937-552a-4993-851d-8536e62c8b0a

Commit: phpstan/phpstan-src@aae34d9

@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 Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants