PHP
  Home arrow PHP arrow Introducing the Reflection API in PHP 5
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
iPad news and developer info.
Ads by affinity 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Forums Sitemap 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Introducing the Reflection API in PHP 5


By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2010-03-02


    Table of Contents:
  • Introducing the Reflection API in PHP 5
  • Building a sample interface and a basic class
  • Finding the name of a reflected class
  • Finding the constants defined by a reflected class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Summary: In this first part of a series, we'll begin exploring some of the methods included with the Reflection API bundled with PHP 5. The interface allows developers to collect relevant information about a reflected class, including its name, its declared constants and properties, in a extremely straightforward way.

    Introducing the Reflection API in PHP 5
    (Page 1 of 4 )

    Even though PHP is intrinsically a weakly-typed language, as it doesn’t internally impose any constraints on the types of values that can be held by a given variable (with the exception of type hinting and type casting), its introspective capabilities are quite impressive indeed. Native old functions like “is_int(),” “is_string()” and “is_float()” among others, which have been used for years, gave programmers the ability to check at runtime if the value assigned to a variable honors a specified type.

    While it’s fair to say that these and other functions play a relevant role within the introspective facet of the language, the truth is that they fall short and become useless quickly, especially when it comes to analyzing the internal structure of classes and interfaces. Frankly speaking, PHP 4 already included a set of functions that allowed developers to inspect classes at a limited level, and they continue to be widely used in programs today. Unfortunately, with the introduction of a highly-enhanced object model in PHP 5, the limitation imposed by these functions became even more evident.

    The happy side of this story is that, along with its most popular object-oriented bells and whistles, PHP 5 was also packaged with a powerful reflection API. This API takes the language’s introspective abilities to a far more mature stage. What’s more, it includes some convenient methods that permit developers to dissect both classes and interfaces down to their bare bones, which can be much more useful than you might think.

    As with many other features of PHP 5, unquestionably the best place to get an intimate background in its reflection API is the official documentation. Even so, for many lazy programmers (like me), sometimes it’s good to have at hand an additional guide that quickly shows how to use the most relevant methods of the API in question.

    With that idea in mind, in this group of tutorials I’m going to attempt to provide you with a variety of simple code samples that hopefully will get you started using the PHP 5 reflection API -- without having to scratch your head trying to figure out how to work with its methods.

    Are you ready to start digging deeper into the reflection programming interface provided by PHP 5? Then click on the link below and begin reading the next few lines. It’ll be an instructive experience, trust me!



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

       

    PHP ARTICLES

    - MVC and the Zend Framework
    - PHP: Rendering Web Pages Using the Composite...
    - PHP: Creating Dynamic Web Pages with the Com...
    - Secure Encrypting and Decrypting for Your PH...
    - PHP: Creating Single View Objects with the C...
    - PHP: View Object Collections and the Composi...
    - Securing Your PHP Website
    - Determine Link Relevance and Unique Class C ...
    - PHP Composite View Design Pattern: Introduci...
    - Facebook PHP API Applications: A Second Look
    - Secure PHP Programming
    - Facebook PHP API Applications: Basic Introdu...
    - SOAP Servers and Web Services
    - Using XPath, SOAP, and More with Web Services
    - Web Services: SimpleXML


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code

     


     


    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek