PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Chris Tankersley's Blog: Getting Started with Reflection

Note: This article was originally published at PHPDeveloper on 4 September 2010.
PHPDeveloper

Chris Tankersley has a new post to how blog looking at a powerful but sometimes seldom used feature of PHP - Reflection. His post introduces you to some of the basics you can use to have your code find out more about itself.

Reflection is a metaprogramming construct that allows a program to look into itself and do a multitude of different things - gain meaning, watch execution, call code, or even provide feedback. [...] With PHP 5, PHP gained a robust reflection class that allows a developer to gain access to just about every aspect of an object and interact with it. The key is figuring out what is available, and then exploiting it to gain additional benefits.

He gives examples from his project where it uses the ReflectionClass feature to pull in the values of a class including properties and methods in a class (a set of ReflectionMethods). Some code is provided to make the examples a bit more clear.