zoukankan      html  css  js  c++  java
  • 反射api获取源代码

    使用反射 api获取类或者类中方法的源代码

    class ReflectionUtil
    {
    	public static function getClassSource(ReflectionClass $reflection)
    	{
    		$file = $reflection->getFileName();
    		$lines = file($file);
    		$start-line = $reflection->getStartLine();
    		$end-line = $reflection->getEndLine();
    		return implode(array_slice($lines, $start-line - 1, $end-line - $start-line + 1));
    	}
    
    	public static function getMethodSource(ReflectionMethod $reflection)
    	{
    		$file = $reflection->getFileName();
    		$lines = file($file);
    		$start-line = $reflection->getStartLine();
    		$end-line = $reflection->getEndLine();
    		return implode(array_slice($lines, $start-line - 1, $end-line - $start-line + 1));
    	}
    }
    

      两个方法惊人的相似。。。。

    另外

    class Test
    {
    	public function testFunction()
    	{
    		return 0;
    	}
    }
    
    $reflectionClass = new ReflectionClass('Test');
    $reflectionMethod = $reflectionClass->getMethod('testFunction');
    $reflectionMethods = $reflectionClass->getMethods();
    

      其中,$reflectionMethod即为ReflectionMethod类的对象。而$reflectionMethods则为对象的集合。

    $reflectionParameters = $reflectionMethod->getParameters();
    

      其中$reflectionParameters则为ReflectionParameter对象数组。

  • 相关阅读:
    凯撒密文的破解编程实现
    微软ping命令的源代码
    从编程到入侵
    永远的后门
    永远的后门
    奇妙的Base64编码
    用端口截听实现隐藏嗅探与攻击(二)
    奇妙的Base64编码
    Liferea 1.1.2
    Equinox Desktop Environment 1.1
  • 原文地址:https://www.cnblogs.com/buerr/p/7305540.html
Copyright © 2011-2022 走看看