PHPize Online / SQLize Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy
Copy Format Clear
<?php class Test { public $c; function test() { $a = 1; $b = 2; $this->c = $a + $b; return $this->c; } public function test2(string $closure) { $func = new ReflectionFunction($closure); $filename = $func->getFileName(); $start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block $end_line = $func->getEndLine(); $length = $end_line - $start_line; $source = file($filename); $ar = array_slice($source, $start_line, $length); array_pop($ar); array_shift($ar); foreach ($ar as $a) { list($var, $expression) = explode('=', $a); $var1 = eval(trim($expression, '\n\s\;')); var_dump($var, $var1, $expression); } } } $t = new Test(); $tt = $t->test2(Test::test());
Show:  
Copy