Skip to content

CallTimePassByReferenceSniff ignores functions with return value #938

@jan-svab

Description

@jan-svab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions