alphabetise class methods


/ Published in: PHP
Save to your folder(s)

pass in a php class and sort the methods alphabetically. great for 'fucking huge' class files where you can't find methods.


Copy this code and paste it in your HTML
  1. <?php
  2. $file = 'path-to-class-file';
  3. $file_contents = @file_get_contents($file);
  4. if ($file_contents !== NULL) {
  5. $file_contents = trim(str_replace(array('<?php', '<?', '?>'), '', $file_contents)); // remove php tags
  6. $file_contents = substr($file_contents, 0, strlen($file_contents)-1); // remove the last chracter - ie. the } bracket
  7. $functions = explode('function ', $file_contents);
  8. $functions_array = array();
  9. foreach ($functions as $f_key => $function) {
  10. $key = trim(current(explode('(', $function)));
  11. if ($f_key == 0) {
  12. $class_start = $key;
  13. }
  14. else {
  15. $functions_array[$key] = $function;
  16. }
  17. }
  18. ksort($functions_array);
  19. echo '<textarea style="width:100%;height:100%">';
  20. echo '<?php' . "\n" . $class_start . "\n\n" . 'function ' . implode('function ', $functions_array) . "\n\n" . '}';
  21. echo '</textarea>';
  22. }
  23. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.