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

Behavior doesn't match PHP when 'use()' variable name matches parameter name #5541

Closed
hussainweb opened this issue Jun 26, 2015 · 4 comments
Closed

Comments

@hussainweb
Copy link

The problem could be said to be the code, but both PHP5/7 and HHVM accept it, but behave differently.

If one of the parameters in a closure has the same name as one of the variables in the use construct, then only one of them can be used. PHP5/7 uses the variable in the use construct whereas HHVM uses the one in the parameters. See this eval: http://3v4l.org/1LTC3

I originally identified this when fixing Guzzle to pass tests on HHVM. See guzzle/guzzle#1143 for the PR. The actual line is at https://github.com/guzzle/guzzle/pull/1143/files#diff-97598a53896efebd2fe6eed1a5f2284aR68.

I tried searching for this issue but couldn't find it. I apologize if it is a duplicate.

@SiebelsTim
Copy link
Contributor

This is stupid actually. I thin emitting a warning would be better than match php.

@hussainweb
Copy link
Author

+1 to the warning, but I think it will also be good to match PHP behaviour. It doesn't look like a valid use case, and hence, I don't think anyone would be using this consciously. It is not really a question of which behaviour is correct. If it is simple to change, it seems certainly better to match PHP.

@fredemmott fredemmott changed the title Inconsistency between PHP5 / HHVM. Behavior doesn't match PHP when 'use()' variable name matches parameter name Jun 26, 2015
@nikic
Copy link
Contributor

nikic commented May 5, 2016

@SiebelsTim PHP 7.1 agrees that this is stupid and will throw a compile-time error:

$ sapi/cli/php -r 'function($x) use($x) {};'
Fatal error: Cannot use lexical variable $x as a parameter name in Command line code on line 1

@ecreeth ecreeth mentioned this issue Dec 30, 2019
@lexidor
Copy link
Collaborator

lexidor commented Sep 16, 2022

I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.

Hhvm has not been able to run php code since the release of 4.0.0. The Hack community almost exclusively uses lambda notation. (Enforced by hhast https://github.com/hhvm/hhast/blob/main/src/Linters/PreferLambdasLinter.hack and the Hack language https://hhvm.com/blog/2019/11/06/hhvm-4.30.html with error_php_lambdas.)

@lexidor lexidor closed this as completed Sep 16, 2022
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

5 participants