Practical Reflection in Java

By | | PHP

4

Via Java.netPractical Reflection in Java (PDF). This is a chapter from O’Reilly’s Hardcore Java. Know it’s not PHP but a worthwhile read anyway. Even if you don’t use Java it’s worth understanding what it’s about, particularily as interop between PHP and Java is starting to look like something PHP developers should be able to cope with, given JSR 223.

Personally think exploring the reflection capabilities of a language is a very good way for existing programmers, with experience of other languages, to pick up new ones. Mark Pilgrim does a great job in Dive into Python for example. Found it a very useful short cut to grasping what Python is about.

Not actually aware of anything discussing PHP’s reflection APIs online right now, other than the manual. PHP4 provides the basics like is_a() and get_class() while PHP5 has a new reflection API (docs currently here). With PHP I guess it begins with print_r() and var_dump() – two very handy ways for programmers to work out what PHP data structures are about.

Terminology Note: in my mental dictionary the terms “reflection” and “introspection” mean the same thing, when it comes to a programming language’s ability to examine itself. Perhaps that needs correction.

Written By:

Harry Fuecks

Harry has been working in corporate IT since 1994, with everything from start-ups to Fortune 100 companies. Outside of office hours he runs phpPatterns: a site dedicated to software design with PHP that aims to raise standards of PHP development. He also maintains Dynamically Typed: SitePoint's PHP blog.

 

{ 4 comments }

Rob Clevenger May 12, 2004 at 11:22 pm

This book from O’Reilly simply rawks. Read this excellent review here: http://www.jaxmagazine.com/itr/buchtipps/psecom,id,283,nodeid,148.html

sike May 12, 2004 at 6:56 pm

upps.. some words missing (:

the reflection api provides some good insight into class layout and organization of librarys or frameworks (provided they use OO).

sike May 12, 2004 at 6:54 pm

the reflection api provides some good
insight into its class layout and organization.
while toying around with it, i found it a nice
exercise writing a quick and dirty xmi writer.
since then i use it from time to time to get a impression
on things im working or to just peek into a libary.

reflection is a neat new feature and i expect it to get a lot of attention in the future (testing frameworks, documentation…)

nucleuz May 12, 2004 at 11:10 am

Just a note on the reflection documentation: the class names has changed – no more underscores in the class names, the basic example should be:
Reflection::export(new ReflectionClass(‘Exception’));
and not
Reflection::export(new Reflection_Class(‘Exception’));
that goes for all the classes in the documentation.

Comments on this entry are closed.