title: Looking for functions with PHP tokenizer
body: <p>Right now, I have a script which uses PHP's tokenizer to look for certain functions within a PHP source code file.  The pattern I am currently looking for is:</p>
  
  <p>T_STRING + T_WHITESPACE (optional) + "("</p>
  
  <p>This seems to match all of my test cases so far except variable functions, which I am ignoring for the purposes of this question.</p>
  
  <p>The obvious problem here is that this pattern produces a lot of false positives, like matching function definitions:</p>
  
  <pre><code>public function foo() {  // foo() should not be matched
  </code></pre>
  
  <p>My question is, <em>is there a more reliable/accurate method for looking at source code and plucking out all the function invocations?</em>  Maybe a better method than using the tokenizer at all?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>In particular, I'm looking to emulate the functionality of the <code>disable_functions</code> PHP directive <em>within a class file</em>.  So, if <code>exec()</code> should be disallowed, I'm trying to find any uses of that function within the analyzed file.  I do realize that variable functions make this terribly difficult, so I am detecting these and disallowing them as well.</p>