In our daily development work, we often use private methods in calling classes. Today I will introduce to you how PHP calls private methods in execution classes through reflection methods. I hope this tutorial can help all friends who are interested. You can come in and take a look. Features a full reflection API, adding the ability to reverse engineer classes, interfaces, functions, methods, and extensions.
#The first step, first Download the PHP reflection method we need to use in this course to call the private method library in the execution class: http://www.php.cn/xiazai/leiku/594 Step 2: After the download is completed Find the php class file we need, unzip it to our local directory, and create a new php file! The third step, after completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "myclass.php";//引入类文件 //通过类名MyClass进行反射 $ref_class = new ReflectionClass('MyClass'); //通过反射类进行实例化 $instance = $ref_class->newInstance(); //通过方法名myFun获取指定方法 $method = $ref_class->getmethod('myFun'); //设置可访问性 $method->setAccessible(true); //执行方法 $method->invoke($instance); ?>
The above is the detailed content of Detailed explanation of PHP reflection method calling private methods in execution class. For more information, please follow other related articles on the PHP Chinese website!