Source code uitlezen van een functie
Rowdy van der Meer
19/07/2012 11:07:45Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$function_name = "testfunction";
$reflectionFunc = new ReflectionFunction($function_name);
$filename = $reflectionFunc->getFileName();
$start_line = $reflectionFunc->getStartLine();
$end_line = $reflectionFunc->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$source = implode("", array_slice($source, $start_line, $length));
$source = highlight_string("<?php \nfunction {$function_name}(" . implode(", ", $parameterArray) . ") \n" . $source . "?>", true);
$output .= "<blockquote>" . $source . "</blockquote>";
?>
$function_name = "testfunction";
$reflectionFunc = new ReflectionFunction($function_name);
$filename = $reflectionFunc->getFileName();
$start_line = $reflectionFunc->getStartLine();
$end_line = $reflectionFunc->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$source = implode("", array_slice($source, $start_line, $length));
$source = highlight_string("<?php \nfunction {$function_name}(" . implode(", ", $parameterArray) . ") \n" . $source . "?>", true);
$output .= "<blockquote>" . $source . "</blockquote>";
?>
Met deze code kan ik vrij snel en makkelijk de source code van een functie ophalen.
Gewijzigd op 19/07/2012 11:09:01 door Rowdy van der Meer