name = $name; } public function enterNode(Node $node) { if ($node instanceof Node\Expr\Variable && $node->name === $this->name) { $this->references[] = $node; } else if ($node instanceof Node\FunctionLike) { // If we meet a function node, dont traverse its statements, they are in another scope // except it is a closure that has imported the variable through use if ($node instanceof Node\Expr\Closure) { foreach ($node->uses as $use) { if ($use->var === $this->name) { return; } } } return NodeTraverser::DONT_TRAVERSE_CHILDREN; } } }