Skip to content

Instantly share code, notes, and snippets.

@komputronika
Created September 9, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komputronika/f92397b4f60870131ef52930faf09983 to your computer and use it in GitHub Desktop.
Save komputronika/f92397b4f60870131ef52930faf09983 to your computer and use it in GitHub Desktop.
Find all functions in a file and return it's names in array
<?php
//--------------------------------
// Example usage:
//--------------------------------
print "<pre>";
print_r( functions_in_file(__FILE__) );
//--------------------------------
// Find functions in a file:
//--------------------------------
function functions_in_file($file, $sort = FALSE) {
$file = join("\n",file($file));
preg_match_all('/function\s+(\w+)/', $file, $m);
$functions = $m[1];
if ($sort) {
asort($functions);
}
return $functions;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment