I’m using token_get_all() to do some static analysis on a php project.
How do I find the scope level for stuff like:
- Finding if the current T_FUNCTION is still inside the T_CLASS being parsed
- Knowing if the scope for T_VARIABLE has already ended
Should I keep a count of ‘{‘ and ‘}’ characters? Is that a safe method?
You might do better to use a parser to build a syntax tree, otherwise the edge cases will become very complex (PHP is a very tricky language that can have other languages embedded in it).
A quick google came up with: PHP-Parser
With a syntax tree you could more easily identify the scope of a function or variable, but it would still require some analysis.