Home >Backend Development >PHP Problem >What are the reflection methods in php

What are the reflection methods in php

coldplay.xixi
coldplay.xixiOriginal
2020-11-03 16:04:131911browse

php reflection methods include: 1. [$reflectMethod=new ReflectionMethod(5f748ff78a6d9b7bda240775875cf697)] Pass in the method name string; 2. [$parameters=$reflectMethod->getParameters()] Get parameter name.

What are the reflection methods in php

##php reflection methods are:

(1)

$reflectMethod = new ReflectionMethod(<方法名>);

Incoming Method name string, returns the ReflectionMethod class instance that controls the target method;

(2)

$parameters = $reflectMethod->getParameters();

Gets the parameter names required by the class. This method returns a two-dimensional array containing all parameter names. Array;

(3)

$name = $parameters->getName();

Returns the single parameter name of the parameter array required for the method to be executed, which can be obtained and assigned one by one through the foreach loop;

(4)

$reflectMethod->invokeArgs(<类实例>,<执行该方法所需参数数组>);

Pass in the class instance and method parameters, execute the method, and return the execution result.

Related learning recommendations:

php programming (video)

The above is the detailed content of What are the reflection methods in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn