PHP class reflection usage example, php Usage example _ PHP Tutorial

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.