Is there a program that can check for unused functions within a PHP file? Ive seen one for ASP, but i need a PSP port
What exactly do you mean, unused functions? Do you mean a function thats in the script but isn't executed?
how about setting up a list of variables at the top of the page like $script1="unused"; $script2="unused"; etc and then when each funtion is called change the variable to "used" somewhere within the function. At the end of the page you can output all the functions which are still at the "unused" stage.
Nice idea Dave! It'd probaly be easier to use an array to set it up though, just less typing. E.g: <?php $functions = array("unused", "unused", "unused"); //Use a function if(strlen("goose") == 5) { echo("Woo, its five characters."); //set the first array value to used $functions[0] = "used"; } //Echo out the array at the end of output echo $functions; ?> PHP: Credit goes to Dave for the idea, not sure if the above will work though. Good luck.
This might be a little cleaner.... Put this at the beginning of each function: $GLOBALS['functions'][__FUNCTION__]++; PHP: Then after your script is over run this: foreach ( $GLOBALS['functions'] as $function_name => $times_called ) { echo "\n<br>$function_name</b> - $times_called"; } PHP: Which should output something like this: get_form_input - 1 set_where - 1 get_promo_code - 2 get_user_location - 1 PHP:
That seems like a lot of code modification and trouble to go through just to find functions that are unused? Surely if you have to manually go through that many lines of code it would be obvious what the script itself is doing, and what functions it doesn't need. Maybe you could post the code as an attachment and have someone look it over? Perhaps in some situations, a function will never be called on certain conditions.. whereas other times, the function is necessary to perform the action it was originally intended.
im perfectly capapble of going through code and checking it... Its a program like http://www.codeproject.com/asp/AspCodeAnalyzer.asp