How to inspect an object

       http://www.php.net/manual/en/book.reflection.php
      

Functions for inspecting an object

Function Description
class_exists($class) Returns TRUE if the specified class has been defined.
get_class($object) Returns the class name of the specified object as a string.
is_a($object, $class) Returns TRUE if the specified object is an instance of the specified class.
property_exists($object, $property) Returns TRUE if the specified object has the specified property.
method_exists($object, $method) Returns TRUE if the specified object has the specified method.

Determine if an object is an instance of a class

      if (is_a($trumpet, 'Product')) { 
        // Code to work with a Product object 
      }
      

Determine if an object has a property

      if (property_exists($trumpet, 'price')) {
        // Code to work with the price property
      }
      

Determine if an object has a method

      if (method_exists($trumpet, 'getPrice')) { 
        // Code to work with the getPrice method 
      }
      

Description

Back