Home arrow PHP arrow Reflecting Abstract Classes and Interface Implementers with the Reflection API

Reflecting Abstract Classes and Interface Implementers with the Reflection API

In this sixth part of a seven-part series, I explain how to use the power of reflection to find out if a class has been defined abstract and final, and if it implements a specified interface. Performing all of these tasks is a straightforward process, so you shouldn’t have major problems using these reflection methods within your own PHP applications.

TABLE OF CONTENTS:
  1. Reflecting Abstract Classes and Interface Implementers with the Reflection API
  2. Review: the hasProperty() and getStaticProperties() reflection methods
  3. Determining if a class is abstract, final and an interface implementer
  4. Checking if a class can be instantiated
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 29, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

When it comes to highlighting the most remarkable features incorporated into PHP 5 a few years ago, undoubtedly its enhanced object model, along with the support for native exceptions and interfaces, are the first things that come to mind. However, as you may have heard, the language also comes with a powerful library commonly known as the Reflection API, which allows developers to perform all sorts of reverse engineering tasks on both classes and interfaces. This process can be far more useful that you might think.

Nowadays, many of the methods included with the reflection API are used widely in well-established frameworks and third-party libraries. This has contributed to the spread of the API’s popularity among developers. It is possible, however, that you still haven’t had the opportunity to take advantage of the functionality given by reflection within your own object-oriented applications, or simply don’t know how to use this API in a really useful manner.

If that’s the case, in this group of tutorials you’ll find a decent number of code samples that will show you how to utilize some of the most important methods bundled with the reflection API. They will let you obtain relevant information about your classes and interfaces with only minor effort.

And speaking of relevant information on classes and interfaces, in the previous chapter of the series I discussed how to use the “hasProperty()” and “getStaticProperties()” reflection methods with a sample class. The first of these methods made it possible to know if a specific property was declared by the particular class, and the second one allowed you (at least in theory) to retrieve all of the class’s static properties in one go.

As I said before, the reflection API can be used for inspecting classes in many different ways. In the lines to come, in fact, I’m going to demonstrate how to employ it to determine if a specified class is concrete or abstract, and if it implements a particular interface. That sounds pretty interesting, right?

Now, it’s time to explore a few more handy methods packaged with 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
   

PHP ARTICLES

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