RSS Feed

Peter Goodman's blog about PHP, Parsing Theory, C++, Functional Programming, Applications,

PHP5 Reflection API

I've been up to some really interesting things with my PHP5 framework. I've got a pretty sweet active records system going on in it. I will dedicate a one or more articles to that later. In the meantime, I was fooling around with PHP's Reflection API to rebuild classes.

One of the main reasons I wanted to do this is because my PHP Manual dashboard widget does have any SPL classes so every time I go up north or don't have access to the internet, I have no way of knowing how to use some of the classes.

What I did was make a very simple function to rebuild as much of the classes as possible. Unfortunately, Reflection doesn't seem to supply the inner code of class methods. The furthest you seem to be able to get is if you have static variables within the function. Although, if anyone knows how to get the contents, that would be great! I was thinking if anything, because line numbers and file names are supplies (but seemingly not for spl classes) that it could just be extracted from the file.

Oh well, here's the little application I made: http://ioreader.com/code/php/reflection.php. If you want the code, just ask :)


Comments


Comment