Page 1 of 1
Class introspection
Posted: Wed Aug 17, 2011 10:29 am
by kasuals
Feel free to move this if it's not the correct forum, however I don't need help with any code just help on how I should tackle a task.
I was handed the grunt task of creating a knowledge base that will take in PHP code, read the classes and create a KB of methods, properties, etc.
My first thought was to read in each file, and then filter out the classes w/regex and place them in the DB for future use.
Then I thought, man that's a lot of regex... so I'm debating on loading each file w/include during the indexing and introspect each class from get_declared_classes. The latter seems like it would be less error prone.
Any thoughts? I have no one to bounce ideas off today, so I figured maybe I could pick your brains.

Re: Class introspection
Posted: Wed Aug 17, 2011 11:52 am
by Jonah Bron
What is the purpose of this project? You might consider using some of the code from documentation generators like DocBlox or PHPDocumentor (DocBlox is more recent).
Re: Class introspection
Posted: Wed Aug 17, 2011 12:15 pm
by kasuals
I've looked at DocBlox, and it's far more than I need for what I'm trying to do. I just need a simple KB for storing classes/interfaces.
I think I'll just do the introspection. Thanks for the suggestions though!
Re: Class introspection
Posted: Wed Aug 17, 2011 12:33 pm
by Jonah Bron
kasuals wrote:I've looked at DocBlox, and it's far more than I need for what I'm trying to do. I just need a simple KB for storing classes/interfaces.
I didn't suggest that you use the entirity of DocBlox, only that you use the part of it that extracts information about classes. What is "KB"?
kasuals wrote:I think I'll just do the introspection.
What do you mean "introspection"? Are you talking about
reflection? That might be a good idea, I didn't think of that. You might run into some problems with name-collision though. The best way to go about that I think is with
runkit_import(). That will import functions and classes from a file (just like include()), while ignoring any code that's
not in a class/function, and overwriting any existing class/functions.
Re: Class introspection
Posted: Wed Aug 17, 2011 12:57 pm
by pickle
KB = Knowledge Base
Re: Class introspection
Posted: Wed Aug 17, 2011 3:38 pm
by kasuals
Yeah, I was going to use reflection to gut each class. Might as well take advantage of those functions.
Thanks for the tip on runkit_import(), that actually solved the issue of name-collision which I was just going over with a buddy. Appreciate the tip on that.
I know everyone complains about "re-inventing the wheel", but without deadlines like most coders have I have the luxury of trial and error. I gain more from the creation process than I do researching others code. I figured there was source out there that would do it for me, and other people's code may enlighten me but I don't absorb concepts well unless I've done it myself from start to finish.
Thanks for the help guys. I'm sure you'll see me griping in the Code forum.
