views:

51

answers:

1

Hello,

How would I with regular expression search for functions which contains the use of a global variable without running "global $var" first?

The files looks like this:

class TestClass
{
    function correctFunc()
    {
        global $var;
        $name = $var->name;
    }

    function invalidFuncIWantToFind()
    {
        $age = $var->user->age;
    }
}

I want to find the function names of all the invalidFuncIWantToFind. At work this would have really speeded up our work but I didn't get how to do it.

A: 

Depending on your Regex implementation, you might be able to use a lookbehind pattern for this. http://www.regular-expressions.info/lookaround.html claims that e.g. the .NET Framework implementation can do this. (Problematic is, that the lookbehind can contain a variable number of letters... this seems to cause trouble). Since I do not have a Visual Studio at hand here, I cannot build a Regex for you, though, sorry.

Jens
Yes, I've been trying to do it with lookbehind but havn't got something working yet.
Marlun