php序列号和反序列化

----------------------

运行结果:

  php序列号和反序列化

 

 

 

 <?php
 
 //$a = scandir(‘/tmp/caoym_temp‘);
 //foreach($a as $v) {
 //  if ($v == ‘.‘ || $v == ‘..‘) {
 //    continue;
 //  }
 //  $cont = file_get_contents("/tmp/caoym_temp/".$v);
 //  $b = unserialize($cont);
 //
 //  var_dump($b);
 //}
 class A {
   public $name = "aaaa";
   public function say() {
     echo $this->name;
   }
 }
 
 $a = new A();
 
 $t = serialize($a);
 echo $t;
 //$t = ‘O:1:"A":1:{s:4:"name";s:4:"aaaa";}‘;
 $b = unserialize($t);
 $b->say();
 var_dump($b);
 
 $methods = get_class_methods(get_class($b));
 var_dump($methods);
 
 $cn = ‘A‘;
 $method = ‘say‘;
 
 $func = new ReflectionMethod($cn, $method);
 
 $f = $func->getFileName();
 $start_line = $func->getStartLine() - 1;
 $end_line = $func->getEndLine();
 $length = $end_line - $start_line;
 
 $source = file($f);
 $source = implode(‘‘, array_slice($source, 0, count($source)));
 // $source = preg_split("/(\n|\r\n|\r)/", $source);
 $source = preg_split("/".PHP_EOL."/", $source);
 
 $body = ‘‘;
 for($i=$start_line; $i<$end_line; $i++)
    $body.="{$source[$i]}\n";

    echo $body;

  

php序列号和反序列化

上一篇:HTML选择器的四种使用方法


下一篇:在ASP.NET Core中使用多个环境