Troubleshooting a PHP Script
Design a Sample MySQL Database
How to Restore Your MySQL Data

Get Information about PHP Objects and Classes

At their simplest, objects are data types. The class is the template (pattern) for the object. PHP provides several functions that you can use to get information about objects and classes:

  • You can check whether a class exists with the following:

    class_exists("classname");
  • You can test whether a property exists in a specific class with the following:

    property_exists("classname","propertyname");
  • You can find out the properties, with their defaults, and the methods defined in a class with the following statements:

    get_class_vars("classname");
    get_class_methods("classname");

    The get_class_ functions return an array. The properties array contains the property name as the key and the default as the value. The methods array contains numeric keys and the names of the methods as values. If a property or method is private, the function will not return its name unless it is executed from inside the class.

  • You can test whether an object, its parents, or their implemented interfaces were created by a specified class using the instanceof operator, added in PHP 5, as follows:

    if($objectname instanceof "classname")
  • You can find out the current values of the properties of an object with the following function:

    get_object_vars($objectname);

    The function returns an array containing the current values of the properties, with the property names as keys.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Display Content in a Web Page with PHP
PHP MySQL Functions
How to Add MySQL Accounts
How to Use PHP to Make a Switch for HTML5 and CSS3 Programming
How to Identify What MySQL Accounts Currently Exist
Advertisement

Inside Dummies.com