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

What are the reflection methods in php

coldplay.xixi
Release: 2023-03-07 07:10:02
Original
1941 people have browsed it

php reflection methods include: 1. [$reflectMethod=new ReflectionMethod()] 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(<方法名>);
Copy after login

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

(2)

$parameters = $reflectMethod->getParameters();
Copy after login

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

(3)

$name = $parameters->getName();
Copy after login

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(<类实例>,<执行该方法所需参数数组>);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template