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

Invalid VarError with usage of references #31

Closed
Seldaek opened this issue Dec 10, 2015 · 2 comments
Closed

Invalid VarError with usage of references #31

Seldaek opened this issue Dec 10, 2015 · 2 comments
Assignees
Labels
bug A crash in Phan, a recent change causing incorrect analysis results, etc.
Milestone

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Dec 10, 2015

I got a minimal repro case for this:

<?php

class Test {
    protected $capture;

    function foo($command, &$bar = null) {
        $this->capture = count(func_get_args()) > 1;
        if ($this->capture && !is_callable($bar)) {
            $bar = 'bar';
        }
    }

    function foo2(&$bar) {}
}

(new Test)->foo('cmd', $undef);
var_dump($undef);

(new Test)->foo2($undef2);
var_dump($undef2);

Phan outputs:

test.php:17 VarError Variable $undef is not defined
test.php:20 VarError Variable $undef2 is not defined

However, php executes this just fine and outputs 'bar' & NULL. Passing the variables by reference defines them even if they are not assigned by the callee. get_defined_vars() also confirms that.

@Seldaek Seldaek changed the title Invalid VarError with complex usage of references Invalid VarError with usage of references Dec 10, 2015
@morria morria added the bug A crash in Phan, a recent change causing incorrect analysis results, etc. label Dec 10, 2015
@morria morria added this to the 1.0 milestone Dec 10, 2015
@morria morria self-assigned this Dec 11, 2015
@morria morria closed this as completed in bee8702 Dec 11, 2015
@Seldaek
Copy link
Contributor Author

Seldaek commented Dec 11, 2015

Cool thanks for the quick turnaround, I'll try to do another pass over the weekend and look at the less common errors to see if I find any other false positives :)

@morria
Copy link
Member

morria commented Dec 11, 2015

That sounds great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash in Phan, a recent change causing incorrect analysis results, etc.
Projects
None yet
Development

No branches or pull requests

2 participants