Home arrow PHP arrow Getting Information on a Reflected Class with the Reflection API

Getting Information on a Reflected Class with the Reflection API

In this second part of a series, I explore some handy methods of the PHP Reflection API. They allow you to retrieve miscellaneous information about a class, including its name and containing file, as well as its starting and ending lines.

  1. Getting Information on a Reflected Class with the Reflection API
  2. Review: using the PHP 5 reflection API
  3. The getDefaultProperties() and getDocComment() reflection methods
  4. The getStartLine(), getEndLine() and getFileName() methods
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
March 03, 2010

print this article



Overlooked by many developers, the Reflection API that comes with PHP 5 is a powerful reverse-engineering extension of the language that permits developers to analyze, inspect and retrieve valuable information about selected classes and interfaces by means of a set of convenient methods.

So, if you’re a PHP programmer interested in learning how to put this API to work for you, then this article series might be the material that you’re looking for. In its tutorials you’ll be provided with a decent number of code samples aimed at demonstrating how to use the most relevant reflective methods included with the API.

And now that you’ve been introduced to the goal of the series, it’s time to review the topics that were discussed in the first installment, taking into account the possibility that you haven’t read it yet. So, to put it simply, in that article I coded a couple of scripts that showed how to obtain the name of a reflected class and the values assigned to its unique constant via the “getName(),” getConstant()” and “getConstants()” reflection methods.

Despite their simplicity, these introductory examples demonstrated the remarkable introspective capabilities offered by the reflection API when used in an object-oriented environment. However, as you might have guessed, the API comes bundled with many other methods that deserve a close analysis as well.

With that premise in mind, in this second episode of the series I’m going to show you how to get miscellaneous information about a reflected class, including things like its starting and ending lines within its containing file, the interfaces that the class implements, and so forth.

Now, let’s leave the preliminaries behind us and continue to explore a few more handy methods provided by the PHP 5 reflection API. Let’s get going!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: