Home arrow PHP arrow Page 4 - Checking Native and User-Defined Classes with the Reflection API

Checking native and user-defined classes with the isUserDefined() reflective method - PHP

Welcome to the final part of a series on the Reflection API. Through a decent variety of functional code samples, this series shows you how to take advantage of the power offered by reflection to analyze the internal structure of your classes and interfaces by using an object-oriented approach.

  1. Checking Native and User-Defined Classes with the Reflection API
  2. Review: a quick look at some previous examples
  3. Working with the isInternal() method
  4. Checking native and user-defined classes with the isUserDefined() reflective method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
April 05, 2010

print this article



As with many other reflection processes shown in the other tutorials of this series, checking to see whether or not a given class is user-defined is only a matter of calling the appropriate reflective method. In this case, the method that will get this job done is called "isUserDefined()," and an example of its use is included below:

// create instance of 'User' class

$user = new User();



// create instance of Reflection class and pass in 'User' class as an argument



// check if the reflected class is a user-defined class

if ($reflector->isUserDefined())


    echo 'Reflected class is a user-defined class'; // displays 'Reflected class is a user-defined class'




    echo 'Reflected class is not a user-defined class';


There you have it. Now, if you try the above script, it'll display a neat message on screen informing you that the "User" class is indeed a user-defined one. Definitely, grasping how this last method does its thing isn't brain surgery, but it should give you a more exact idea of the impressive capabilities offered by the PHP reflection API.

And last but not least, if you're looking for a full reference for the API, I strongly recommend that you look up its official documentation, which is always the best source of information.

Final thoughts

It's hard to believe, but we've come to the end of this series. Hopefully, its tutorials have been pretty instructive. You learned how to work with some of the most important methods that come packaged with the PHP 5 reflection API, which can be much more helpful than it appears at first glance.

While it's fair to say that all of the code samples shown in this series are only "tutorial examples," they should give you a clear idea of how to take advantage of the power of reflection when developing real-world applications. The moral of this story is simple: if you need to analyze in depth the internal structure of classes and interfaces, the reflection API is by far the best option to pick at the present time.  

See you in the next PHP tutorial!

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