Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Having learned the syntax of defining, using, and extending object types, in this section, you will examine utilities to leverage OO programming. Utilities enable you to manage objects in the procedural programming structures. Table 8-3 qualifies the PHP predefined functions that enable you to evaluate and obtain information about object types and object instances.
| Function Name | Description |
| class_exists() | The function checks if a class is defined in the current environment scope. It returns a Boolean true if the object type is defined or false when not. You have an optional second parameter that has a default true value, which means that it attempts to run the __autoload() function when the class doesn’t exist in the environment. You can set the optional parameter to false when you want to disable the __autoload() function call. It has this pattern:
bool class_exists( string class_name [, bool autoload]) |
| get_class() | The function returns the object type of an object instance. It has two behaviors—one inside an object and the other outside. When you use the get_class() function in an object instance, you do not provide an actual parameter because it assumes that you’re referring to the current object instance. An external call to the get_class() function requires that you provide an object as a formal parameter. If you provide an actual parameter that is not an object, it will return a null string, which is interpreted as a Boolean false. It has the following pattern:
string get_class(
[ object obj_name])
|
| get_class_methods() | The function returns an array of class functions that are publicly accessible. As of PHP 5.1, this function ignores functions with private or protected access modifiers. If there are no publicly accessible class functions, it will return an empty array. The actual parameter can be a string that maps to a valid class definition or a variable containing an instance of a class definition. It has the following pattern:
array get_class_methods(
mixed obj_name)
|
| get_class_vars() | The function returns an array of class variables that are publicly accessible. As of PHP 5.1, this function ignores functions with private or protected access modifiers. If there are no publicly accessible class variables, it will return an empty array. The actual parameter can be a string that maps to a valid class definition or a variable containing an instance of a class definition. It has the following pattern:
array get_class_vars(
string class_name)
|
| get_declared_classes() | The function returns an array of declared classes in the environment. The declared classes are relevant to the libraries that you’ve loaded through directives in your php.ini file. Appendix D demonstrates how you can use this predefined function and lists the typical classes in a PHP 5.1 environment. It has the following pattern:
array get_declared_classes() |
| get_declared_interfaces() | The function returns an array of declared interfaces in the environment. The declared interfaces are relevant to the libraries that you’ve loaded through directives in your php.ini file. Appendix D demonstrates how you can use this predefined function and lists the typical interfaces in a PHP 5.1 environment. It has the following pattern:
array get_declared_interfaces() |
| get_object_vars() | The function returns an array of object instance variables that are publicly accessible. As of PHP 5.1, this function ignores object instance variables with private or protected access modifiers. If there are no publicly accessible object instance variables, it will return an empty array. The actual parameter must be a variable that holds an instance of an object. It has the following pattern:
array get_object_vars(
object obj_name)
|
| get_parent_class() | The function returns the parent class of an instance of a subclass. It has the following pattern:
string get_parent_class(
object obj_name)
|
| interface_exists() | The function checks if an interface is defined in the current environment scope. It returns a Boolean true if the interface is defined or false when not. You have an optional second parameter that has a default true value, which means that it attempts to run the __autoload() function when the interface doesn’t exist in the environment. You can set the optional parameter to false when you want to disable the __autoload() function call. It has this pattern:
boolean interface_exists( string name [, boolean autoload]) |
| is_a() | The function checks if an object instance is an implementation of an object type. When the object instance is an implementation of the object type, the function returns a true value. When it is not, the function returns a false value. It has the following pattern:
boolean is_a( object obj_name , string object_name) |
| is_subclass_of() | The function checks if an object instance is an implementation of a subclass of an object type. When the object instance is an implementation of a subclass of an object type, the function returns a true value. When it is not, the function returns a false value. It has the following pattern:
boolean is_subclass_of( object obj_name , string subclass_name) |
| method_exists() | The function checks if a function has been implemented in an object instance. When the object contains an implemented function, the function returns a true value. When it is not, the function returns a false value. It has the following pattern:
boolean method_exists( object obj_name , string function_name) |
| property_exists() | The function returns a true value if a class property is found, provided that it is publicly accessible. When there is not a matching property, it will return a false value. It has the following pattern:
array property_exists( object obj_name , string property_name) |