views:

65

answers:

3

I'm profiling an app that has a boat load of functions in many files and I'm trying to isolate functions that don't get called ever.

Any ideas before I proceed?

+2  A: 

I don't believe there is an easy way to do this. print_r(get_defined_functions()); in a file that can be included at the end of every file or in a global. Collect the output and do searches on all your files for function calls. This will isolate out your functions.

Or

Move all the functions to an include file, comment out the functions and then allow the application to error. As you get errors for those functions un-comment the functions to resolve the errors. At the end of all your checks you'll have a list of commented functions that aren't utilized.

Either way it's not easy.

Brant
Thanks for the get_defined_functions() tip. Looks like your first method could be it.
zaf
A: 

This should be easy if you're using an IDE that lets you search the entire project. Just Ctrl + F the function name with an opening bracket and if you only find one hit then you know the function is never called anywhere.

eg. Search for uselessfunction(

Otherwise you'll have to do this manually in each file.

Lotus Notes
There are 450+ functions. It won't be much fun doing it manually, eh?
zaf
This won't work. PHP allows string-based invocation of functions in several ways. `array_map( 'trim', $arr );` or `$func = 'trim'; $func();` or `call_user_func( 'trim', $string );`. All of these would sneak past your ctrl + f scheme.
Peter Bailey
+1  A: 

Several links from http://qualityassuranceinphpprojects.com/pages/tools.html, namely

http://github.com/sebastianbergmann/phpcpd

http://github.com/sebastianbergmann/phpdcd

http://phpmd.org/about.html

eyescream
Brilliant, phpdcd "Dead Code Detector" seems to be the answer.
zaf