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

Cannot use lexical variable #1855

Closed
SignpostMarv opened this issue Jan 29, 2019 · 5 comments
Closed

Cannot use lexical variable #1855

SignpostMarv opened this issue Jan 29, 2019 · 5 comments

Comments

@SignpostMarv
Copy link
Contributor

using whichever version is on the PHPStan playground at the time of writing

Summary of a problem or a feature request

Under php 7.0, variable/param name collisions seem to be silently ignored, but under php 7.1 onwards it's identified as a fatal error.

Code snippet that reproduces the problem

"Cannot use lexical variable $foo as a parameter name"

<?php
declare(strict_types=1);

$foo = 'bar';
  
$a = function (string $foo) use ($foo) : string {
  return $foo;
};

echo $a('baz');

Expected output

An error similar to that which occurs with an "unused use", e.g. https://phpstan.org/r/cff41209-747e-414d-8ef3-60fa360f5bfd

@SignpostMarv
Copy link
Contributor Author

also tracking in psalm on vimeo/psalm#1256

@ondrejmirtes
Copy link
Member

Thanks. Adding this as another thing that should be detected:

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+5: Redefinition of parameter $foo.
Full report
Line Error
5 Redefinition of parameter $foo.

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src#2755

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 Dec 23, 2023
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

3 participants