PHP class reflection usage instance, php Usage instance. PHP class reflection usage example. php Usage example this article describes PHP class reflection usage. Share it with you for your reference. The specific implementation method is as follows: this example provides an example of PHP Reflection usage for each channel, and an example of php usage.
This article describes the reflection usage of PHP classes. Share it with you for your reference. The specific implementation method is as follows:
In this example, corresponding classes are obtained for each channel to perform corresponding operations. The details are as follows:
The code is as follows:
Foreach ($ this-> chs as $ ch ){
$ ClassName = $ this-> chsMap [$ ch];
If ($ className) {// if it is a valid class name
// Obtain the reflection class
$ Class = new ReflectionClass ($ className );
// Obtain the class method
$ Recd = $ class-> getmethod ('exist ');
// Generate a class instance
$ Instance = $ class-> newInstance ($ this-> qq, $ this-> ip );
// Execution method
$ Result [$ ch] = $ recd-> invoke ($ instance );
}
}
I hope this article will help you with PHP programming.
How to obtain an object type in php
To get an object type, use the gettype () function:
To obtain the instance of the class of an object, use the get_class () function:
To obtain the methods and attributes of a class or object, use reflection:
GetProperties (); // A group of objects will be returned. for usage instructions, refer to the PHP manual $ ref-> getMethods (); // A group of objects will be returned, for usage instructions, see The PHP manual $ obj = new MyClass (); $ ref = new ReflectionObject ($ obj); $ ref-> getProperties (); $ ref-> getMethods ();
Php class usage
Class myclass
{
Function showerror ($ msg)
{
$ Msg = trim ($ msg );
Echo"