2

UPDATE: resolved with a PHP parser. Let's reopen so that I can answer and accept.


I'm considering moving a PHP site to a new host. I've got a shared plan on both source and target hosts, therefore limited access to PHP customization.

Certain PHP function families (openssl, mcrypt, gd to name a few) may not be available on the new host. In order to match the API surface against the host, I'd like to statically list all PHP functions, both standalone and class methods, that my files reference.

There's very little dynamic code, so API references that are hidden behind eval are not a concern. Static analysis would be sufficient.

I've tried phpCallGraph with -p and Doxygen - both produce incomplete coverage. Are there any other tools to that effect out there, please?

EDIT: the solution in this question is utterly inapplicable. It's called functions I'm after, not defined ones.

EDIT2: I would like to avoid retesting the whole site. Just the portions that depend on module provided functions.

Community
  • 1
  • 1
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • exactly how do you "look" for an api on a server? it's http... you can try firing off an infinite number of key=value pairs as query strings and post bodies, but you're not likely to have much luck getting anything other than 4xx/5xx codes. – Marc B Apr 24 '14 at 18:05
  • I was going to specifically spot-test code paths that depend on obscure APIs. It's my site, I know the logic pretty well. I also know that testing for 100% coverage is not something I wanna do :) – Seva Alekseyev Apr 24 '14 at 18:07
  • 1
    By "API references", do you just mean "built-in functions"? And by "function families", you mean "extensions", right? – IMSoP Apr 24 '14 at 18:07
  • Are you looking in particular to list called functions from PHP modules in particular? Usually applications should have a well-defined set of required modules, and they should bomb out if they are not loaded. These are usually noted in set-up files and the like, so you can go to a host and ask them what modules they support. – halfer Apr 24 '14 at 18:08
  • @IMSoP: Right. Bad choice of words. Fixed. – Seva Alekseyev Apr 24 '14 at 18:08
  • @halfer: There should be, but there isn't :) The codebase evolved over quite some time. – Seva Alekseyev Apr 24 '14 at 18:09
  • Xdebug & a fun afternoon with WinCacheGrind? :-) – jonnu Apr 24 '14 at 18:10
  • http://stackoverflow.com/questions/3881588/php-get-called-functions-list – Tyler Carter Apr 24 '14 at 18:27
  • Um, that's dynamic analysis. I'm after static. – Seva Alekseyev Apr 24 '14 at 18:51
  • This seems like a good fit for the new [Software Recs](http://softwarerecs.stackexchange.com/) site. – halfer Apr 24 '14 at 20:44
  • Solved with [PHP-Parser](https://github.com/nikic/PHP-Parser) and an hour of work. – Seva Alekseyev Apr 24 '14 at 20:49

1 Answers1

0

Solved with PHP-Parser and an hour of work.

Go through all PHP files in a folder, parse each one. Go through the parse tree, identify function calls, store the function names. Identify function definition statements, store the names of these. At the end, subtract the latter from the former, dump the result. Same for class method invokations.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281