1

If a C/C++ programmer wants to tidy out a large C or C++ project, then he can remove some code files (*.c, *.h, *.cpp, ...) that he thinks as possibly orphaned. When he starts the compiler, and it runs without errors, then he was right. When the compiler throws errors, because the removed files are needed, then the programmer knows for sure that a particular code file is really needed by the large project.

We have a large web project here, that was written in PHP. It consists of a lot of PHP files and image files. The problem is that there is no compiler for a large PHP based web project.

One person here read an article 10 or 15 years ago. This article showed a solution to get the same result for a PHP project as a C/C++ programmer with a C/C++ project would get using his compiler. He remembered only the mere fact that this solution exists, but he lost that article and he forgot the solution in detail.

Does anybody know whether such a solution exists? If so, what is the name? Are there URLs? Key words for search engines etc.?

1
  • try to grep for include and require and work from there Commented Apr 24, 2014 at 12:27

1 Answer 1

3

An exact solution doesn't exist. The reason is that php is free to do any includes it wishes, based on any output it can produce. It's impossible (literally) do generically determine what that can be.

All is not lost however, because typically php programs doesn't use this, so we can find a set of files that are needed and assume the rest probably aren't. Mostly we will get lucky.

The right google term is static analysis. I haven't used any such tools for php, so can't give you specifics but they do seem to exist.

Another approach would be to make a few test cases covering the functionality of you project and then get a code coverage report from that. This is even more likely to miss stuff, but might still give some good insight in what parts are used.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Just to add an example for why it's impossible: include $_GET['foo']; Since this is a legal statement, it's virtually impossible to reason that any particular file won't ever be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.