HomePHP Checking Native and User-Defined Classes with the Reflection API
Checking Native and User-Defined Classes with the Reflection API
Welcome to the final part of a series on the Reflection API. Through a decent variety of functional code samples, this series shows you how to take advantage of the power offered by reflection to analyze the internal structure of your classes and interfaces by using an object-oriented approach.
And now that you've been introduced to the main goal of this series, I'd like to spend a few moments refreshing the topics that were covered in the last article. In that tutorial I explained how to utilize a couple of methods included with the reflection API to determine if a specified class was declared abstract or final (or both) and if the class in question implemented a specified interface.
All of these reflective tasks were carried out by means of a clean object-oriented interface, which made the whole introspection process easy. Besides, the reflection API comes with many other handy methods that allow you to perform all sorts of reverse engineering processes on a given class. There are so many, in fact, that they can't all be covered in this series.
In this last tutorial, however, I'm going to explain how to use reflection to find out whether a specific class is native or user-defined. And, if that's not good enough for you, you'll also learn whether the class can be traversed via a "foreach" construct.
Ready to tackle the final chapter of this educational journey on exploring the PHP 5 reflection API? Then start reading right now!