public static List<Variable> getVariableReferencesInScope( final Variable variable, final boolean includeSelf) { final List<Variable> variables = new ArrayList<Variable>(); Variable variableDecl = null; if (!variable.isDeclaration()) { PsiElement psiElement = variable.resolve(); if (psiElement instanceof Variable) { variableDecl = (Variable) psiElement; } } else { variableDecl = variable; } if (variableDecl == null) { return variables; } Method method = PsiTreeUtil.getParentOfType(variable, Method.class); PhpPsiUtil.hasReferencesInSearchScope( method.getUseScope(), variableDecl, new CommonProcessors.FindProcessor<PsiReference>() { @Override protected boolean accept(PsiReference psiReference) { PsiElement variableRef = psiReference.getElement(); if (variableRef instanceof Variable) { if (includeSelf) { variables.add((Variable) variableRef); } else { if (!variableRef.equals(variable)) { variables.add((Variable) variableRef); } } } return false; } }); return variables; }