Use of PHP Reflection

Source: Internet
Author: User

When it comes to reflection reflectionclass everyone probably knows that by encapsulating the various properties of a class for the user to use.

I was very confused at the beginning, since the name of the class know why to use reflection, the online others to give me the example of the reflection is purely for reflection, and then see the Kohana framework of the source of the use of reflection, I understand, a word: Reflection can be used to get some properties that you cannot get from the name of the class.

Code snippet:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15           $extension = ‘class ‘.$class.‘ extends ‘.$class.‘_Core { }‘;            // Start class analysis             $core = new ReflectionClass($class.‘_Core‘);            if ($core->isAbstract())             {                 // Make the extension abstract                 $extension = ‘abstract ‘.$extension;             } //var_dump("extension:".$extension);             // Transparent class extensions are handled using eval. This is             // a disgusting hack, but it gets the job done.             eval($extension);

Here we get the attribute that this class is not an abstract class. And of course there are other properties we can use

Can be obtained in the official PHP reflection document.

The summary is that if you need to instantiate a class, you want to know about other property information about the class in addition to the name of the class, so you should use reflection to get it.

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.