How to call private methods of a class in php
This article mainly shows you "how to call private methods of a class in php". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to call private methods of a class in php".
The concrete steps of calling the private method of the class in php: 1, reflect through the class name; 2, instantiate through the reflection class; 3, get the specified method through the method name; 4, set accessibility; 5, execute the method.
This article operating environment: windows10 system, php 7.1, thinkpad T480 computer.
How should we call private methods of a class in php? We know that there is a complete reflection API in php, and the ability to reverse engineer classes, interfaces, functions, methods, and extensions is added, so we can call and execute private methods in a class through reflection.
Next, let's take a look at the specific code implementation.
Code implementation:
These are all the contents of the article "how to call private methods of a class in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!