And for a last suggestion, you could use regular expression to parse the function/class definitions.
Hmm, after looking at the documentation, I think that token_get_all should work. I thought that REGEX may not accurate as it might be confused by string variables. If you get any idea of using REGEX please help me also . Thanks so much.