Practical Reflection in Java

    Harry Fuecks
    Share

    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.