Russell N. Nelson - rnnelson wrote:
Maybe there's a better tool to tell you what function is defined in what class in PHP, but I couldn't find one in the time it would take me to write it, so I wrote it. It's not even a screenful. Give it the class definitions, in class hierarchy order, on the command line.
That restriction isn't too friendly.
It will pull out the class name and function names, and tell you which function is actually being implemented by which class. It doesn't pay any attention to parent::self() calls, so you should watch out for them. -russ
#!/usr/bin/python
import sys, re
functions = {} classes = {} cl = None for fn in sys.argv[1:]: for line in open(fn): match = re.match(r'(abstract\s+)?class\s+(.*?)\s+(extends\s+(.*?)\s+)?{', line) if match: cl = match.group(2) supercl = match.group(4) classes[cl] = supercl if supercl: classes[supercl] # superclass should already be exist
Also note, some files include both the class and the superclass, so "give in class hierarchy order" may not be possible (I don't know if there's any file that includes the child before the parent, though).
match = re.match(r'\s*(public\s+|static\s+)?function\s+(.*?)\(', line)
I understand you may not want protected or private functions, but this regex will also miss the 536 functions that are public static, and the 7 that are static public.
if match: # we have a function definition. funct = match.group(2) functions[funct] = cl
keys = functions.keys() keys.sort() for key in keys: print key,functions[key]
If you are adventurous, you may want to add an option to create a file similar to parent.classes in check-vars.php Functions are already being tracked, so it shouldn't be too hard.