Skip to content

Create function parameter assignment sniff #104

Open
@aik099

Description

@aik099

Idea of the sniff is to locate function/method parameter that's value is replaced within the method. This is bad idea, because any code that reads parameter value expects original value to be retrieved, but instead is getting last modified value version.

Implementation plan:

  1. listen for T_FUNCTION token
  2. get parameters of that function, that aren't passed by reference
  3. lookup names of these parameters in function body and T_WHITESPACE (optional) + assignment tokens after it

P.S.
The $$var code won't be supported, because it's hard to trace back statically.

Examples

function functionName($param1, &$param2)
{
    $param1 = 'new value' . $param1; // not allowed
    $param2 = 'new value'; // allowed, because value is passed by reference
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions