MustaphaHadid
9/26/2017 - 1:04 PM

get_functions_in_file.php

<?php

/**
 * Returns an array of function names in a file.
 *
 * @param (string) $file
 *   The path to the file.
 *
 * @param (bool) $sort
 *   If TRUE, sorts results by funciton name.
 */
function get_functions_in_file($file, $sort = FALSE) {
  $file = file($file);
  $functions = array();

  foreach ($file as $line) {
    $line = trim($line);
    if (substr($line, 0, 8) == 'function') {
      $functions[] = substr($line, 9, strpos($line, '(') - 9);
    }
  }

  if ($sort) {
    asort($functions);
    $functions = array_values($functions);
  }

  return $functions;
}