Home arrow PHP arrow Working with Reflected Properties with the Reflection API

Working with Reflected Properties with the Reflection API

In this fourth part of a seven-part series, I demonstrate how to use the PHP reflection API to retrieve useful information about the properties declared by a specific class. Reflection allows you to do more with properties of a class than determine their visibility or learn the values assigned to them, but that's what we'll be covering here.

  1. Working with Reflected Properties with the Reflection API
  2. Review: working with reflected methods
  3. Manipulating properties of a reflected class
  4. Getting all the properties of the User class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
March 15, 2010

print this article



In case youíre not aware of it, among the many enhancements and helpful features that were added to PHP 5, thereís one that has been unfairly overlooked by many developers. This might be because at first glance it doesn't seem to be as useful as the others. Yes, as this articleís title suggests, Iím talking about the reflection API, a powerful set of methods that permits you to perform an in-depth reverse engineering process on both classes and interfaces, in this way expanding the languageís introspective capabilities.

Fortunately, the API has progressively come out of the shadows of indifference, and nowadays its popularity has grown considerably. It's being used in a huge variety of scenarios and situations, ranging from creating low-level dispatcher classes in MVC-based frameworks, to building dependency injection containers.

Of course, it's possible that you still havenít had the chance to explore this API in depth and discover what it can do for you. If thatís the case, in the course of this article series, Iím going to show you how to work with its most relevant methods, so you can start taking advantage of reflection within your own web applications.

I left off the previous tutorial explaining how to use the reflection API to get relevant information about the methods defined by a sample class, including the ability to learn if the methods in question were declared public, protected or private. However, the power of reflection doesnít stop here; it allows you to analyze class properties with a similar level of introspection.

If this topic has caught your attention, in the following lines Iím going to code some friendly examples to demonstrate the functionality of the PHP reflection API when it comes to inspecting properties of a class.

Now, letís get rid of the dull theory and learn more about using reflection in PHP 5. 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: