The reflection in PHP tells you in detail

Source: Internet
Author: User
This article describes the reflection in PHP, we do not quite understand the PHP reflection can be seen to understand, this article simply tells the reflection in PHP, nonsense less, let's take a look!

PHP 5 has a complete reflection API that adds the ability to reverse engineer classes, interfaces, functions, methods, and extensions. In addition, the reflection API provides a way to remove document comments from functions, classes, and methods.

Use of reflection in the TP frame

    • 1, reflectionclass::__construct-constructs a Reflectionclass class

Public reflectionclass::__construct (mixed $argument)

2. reflectionclass::newinstanceargs-creates a new class instance from the parameters given, which is passed to the constructor of the class.

public object Reflectionclass::newinstanceargs ([array $args])

3,/thinkphp/library/think/container.php

/**     * Invoke Reflection Execution Class instantiation support Dependency Injection     * @access public     * @param  string    $class class name     * @param  array     $ VARs  parameter     * @return Mixed     *    /Public Function Invokeclass ($class, $vars = [])    {        try {            $ reflect = new Reflectionclass ($class);            $constructor = $reflect->getconstructor ();            Injection $args to support dependency            = $constructor? $this->bindparams ($constructor, $vars): [];            Return $reflect->newinstanceargs ($args);        } catch (Reflectionexception $e) {            throw new ClassNotFoundException (' Class NOT exists: '. $class, $class);        }    }

Related Article

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.