----------------------
运行结果:
<?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("/( | | )/", $source); $source = preg_split("/".PHP_EOL."/", $source); $body = ''; for($i=$start_line; $i<$end_line; $i++) $body.="{$source[$i]} "; echo $body;