Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using regexes to parse code is a REALLY bad idea. Take a look at <a href="http://php.net/manual/en/book.tokenizer.php" rel="nofollow">PHP's Tokenizer</a>, which you can use to parse PHP code into an array of tokens. You can than use that array to find the information you need.</p> <p>You can also look at <a href="https://github.com/Andrewsville/PHP-Token-Reflection" rel="nofollow">PHP-Token-Reflection's source code</a> as an example of how to get meaningful information from those tokens.</p> <p>Basically, you would need to find <strike>T_PARENT occurrences</strike> T_STRING occurrences with 'parent' as the string contents, followed by T_DOUBLE_COLON, followed with another T_STRING that contains the method name, than go forward and start counting the depth of the parentheses - whenever you get to an '(', increase the counter by one. Whenever you get to an ')', decrease the counter by one. Keep a record of everything you find in the process until the counter gets back to 0.</p> <p>Something like that should work (not actually tested):</p> <pre><code>&lt;?php $tokens = tokens_get_all(...); for ($i=0, $size = count($tokens); $i &lt; $size; $i++( { if ($tokens[$i][0] === T_STRING &amp;&amp; $tokens[$i][1] === 'parent' &amp;&amp; $tokens[++$i][0] === T_DOUBLE_COLON &amp;&amp; $tokens[++$i][0] === T_STRING) { $method = $tokens[$i][1]; $depth = 0; $contents = array(); do { $contents[] = $token = $tokens[++$i]; if ($token === '(') { $depth++; } elseif ($token === ')') { $depth--; } } while ($depth &gt; 0); echo "Call to $method with contents:\n"; print_r(array_slice($contents, 1, -1)); // slices off the opening '(' and closing ')' } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload