Home arrow PHP arrow Getting More Info on Reflected Properties with the Reflection API

Getting More Info on Reflected Properties with the Reflection API

In this fifth part of the series you will learn a couple of additional methods included with the PHP reflection API. The first one will allow you to check the existence of a specified class property, and the second one will permit you to retrieve all of the static properties defined by that class at once.

TABLE OF CONTENTS:
  1. Getting More Info on Reflected Properties with the Reflection API
  2. Review: getting basic information about class properties with reflection
  3. Checking for a class property's existence with the hasProperty() reflection method
  4. Retrieving all of the static properties of a class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
March 22, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Frankly speaking, the powerful reflection library that comes included with PHP 5 is one of those features that you, as a web developer, canít live without once youíve discovered its real functionality. While is fair to say that in the old days of PHP 4, the language already provided some native functions that allowed developers to achieve a decent level of introspection in classes and objects, the reflection API permits you to analyze the internal structure of classes and interfaces by using an intuitive object-oriented approach, or expressed in other words, you can use reflective classes that inspect other classes. What else can you ask for?

Well, feature-hungry programmers (and that includes myself, of course) will always ask for more. In its current version, however, the reflection API will let you perform a thorough reverse engineering process on your own classes, such as knowing what methods and properties they define, the level of visibility assigned to those members, and even instantiate directly classes from client code without having to explicitly write any ďnewĒ constructs.

Naturally, if youíve been a loyal follower of this series and already went through all of the articles that precede this one, then you're already familiar with using some of the most important methods included with the reflection API. In those tutorials I coded a few simple examples that showed, for instance, how to get all of the methods declared by a class and how to determine if the methods in question were public, protected or private.

Also, I left off the last installment discussing how to retrieve all of the properties declared by the aforementioned class, along with their level of visibility, which was a straightforward process. Of course, as you might have guessed, the ability to manipulate class properties via reflection doesnít stop here. To prove this, in the lines to come Iím going to demonstrate how to determine if a specified property exists within a class, and whether or not the class defines any static properties.

So, now that you know what to expect from this part of the series, itís time to explore a few more handy methods bundled with the PHP reflection API. Letís jump in!



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