NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Method to determine if a function is referenced anywhere


Joined: 10 Apr 2014
Posts: 52
Reply with quote
Seeing as there is a feature in phped to search within a project for any usages of a function (right-click on function / find usage), is there a way to run a site wide scan somehow that would look for unused functions, and/or unused images?

I have a project that I have been working on for many years and through evolution with new features, modules, etc. we always seem to be left with unused functions that are just not used anymore. Periodically I will take the time to use the feature in phped to look for usages, and I'll also do grep searches on the command line to figure this out, but it would be slick if phped could just tell me this somehow.

Not sure if I'm making sense here, or if this is possible, but i would love it if it was.
View user's profileFind all posts by probc2Send private message


Joined: 22 Apr 2014
Posts: 23
Reply with quote
I don't see how such a feature could be created, or at least how it could be trusted. It is easy to call a function as a callback in php, for example
Code:
function test () {
   print "this is a test<br>";
}
call_user_func('test');


With the same function you could use this to call it
Code:
$a = 'test';
$a();


It would be extremely hard to get it right all the time. It could give you a list of function but you would not be able to trust that they are not used. But you are right that it would be a good starting point, it would at least remove all functions that are actually used somewhere. Then you could use some kind of logging system in each of those functions to see which one are still in use somehow...

For images, it would be even harder, since I work on multi-language site I often have images loaded this way "image1-".$lang.".jpg" and I have a lot of images that are loaded dynamically from database entries, I would not expect the IDE to know how I load my images.
View user's profileFind all posts by infcSend private message


Joined: 10 Apr 2014
Posts: 52
Reply with quote
Yes I can definately see why I am coming up empty after a number of searches on the internet for such a system. I can only wish i was smart enough to build a system that could scan code and/or a directory and determine if anything is orphaned. Like you said, at least if it come strip out that obvious functions / image files that are clearly in use and leave me with list to manually inspect it would be a great starting point.

With some of my other sites they are small enough that i can keep on top of things and do the necessary cleanup as i go, but this one particular project is many years old and has become fairly fragmented along the way. It's a bear to deal with.
View user's profileFind all posts by probc2Send private message
Method to determine if a function is referenced anywhere
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic