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

CallTimePassByReferenceSniff ignores functions with return value #938

Closed
jan-svab opened this issue Mar 27, 2016 · 3 comments
Closed

CallTimePassByReferenceSniff ignores functions with return value #938

jan-svab opened this issue Mar 27, 2016 · 3 comments

Comments

@jan-svab
Copy link

A line 75 in file CodeSniffer / Standards / Generic / Sniffs / Functions / CallTimePassByReferenceSniff.php contains condition to ignore call time pass by references in functions calls, which have a return value:
|| isset(PHP_CodeSniffer_Tokens::$assignmentTokens[$prevCode]) === true
This is obviously intentional, because it is commented on line 71 as "Also skip if the return value is being assigned to a variable."

However, this causes for example this code not to produce an error:

<?PHP
$foo = Bar(&$fooBar);
?>

Commenting out line 75 makes sniffer correctly alert this code.

This behavior seems wrong to me and eventhough it is obviously intentional, I cannot see any reason why this line is present in source code of the sniffer. Is there any such reason? Or is it some kind of mistake? I'm using this sniffer with line 75 commentend out and it works fine for me.

@gsherwood
Copy link
Member

I went back and had a look at the commit: e4b7736

I installed 2.3.3 and confirmed the error it was trying to fix. Installed 2.3.4 and confirmed it was fixed. Then commented out line 75 in 2.3.4 and the fix was still there and that the unit tests were still passing.

So it looks like that code was added during development but later not needed. It can probably just be removed, but I'll do a bit more testing first.

@gsherwood
Copy link
Member

Probably also worth noting that the code would produce a warning in PHP 5.3, a fatal error in PHP 5.4+, and a syntax error in PHP 7, so we want the error to be reported.

gsherwood added a commit that referenced this issue Mar 29, 2016
@gsherwood
Copy link
Member

I couldn't find any reason for that code there. The assignment scenario is checked down further, so it looks like it was a mistake. Code has been removed and all tests are still passing.

Thanks for finding and reporting this.

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