Home arrow PHP arrow The Reflection API: Working with Reflected Methods

The Reflection API: Working with Reflected Methods

This third part of a seven-part series explores the methods of the PHP Reflection API. You will learn how to take advantage of their functionality to retrieve useful information about the methods defined by a reflected class.

  1. The Reflection API: Working with Reflected Methods
  2. Review: using the PHP reflection API to retrieve information on a class
  3. Retrieving methods of a reflected class
  4. Getting all the public methods of a reflected class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 08, 2010

print this article



One of today's most powerful approaches for retrieving information about the internal structure of classes and interfaces in PHP 5 is via the language's native reflection API. What's more, not only does this API comes packaged with a huge variety of methods that let developers perform all sorts of reverse-engineering tasks using an object-oriented approach, but it offers a flat learning curve.

In reality, knowing whether a method within a specified class is public, protected or private, or determining whether or not a declared property is static, only involves invoking the proper method provided by the API. The entire introspection process is that easy.

Naturally, if you've already read the two previous parts of this series, you're now pretty familiar with using the PHP reflection API to get basic data on a simple interface and its implementing class. In those two articles I demonstrated how to retrieve, for instance, the name, the default properties and constants of a sample reflected class. I also showed how to discover a few other minor details, such as its physical location within the file system.

As I said a moment ago, however, the API provides many other helpful methods for obtaining relevant information about a specific class. These include methods that allow you to know what methods are defined by the class, and their level of visibility.

Assuming that you're interested in learning more about this topic, in the lines to come I'm going to show you how to manipulate reflected methods in a painless way. This process will range from finding out if they're public, protected or private, to invoking them (when possible) directly from client code.

Now it's time to learn a few more useful things about the PHP reflection API. Let's go!

>>> 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: