如何获取最终的PHP代码来替换所有需要并包含他们的代码

First let me apologize if this question was answered before, I just don't seem to find the proper terms to search for it.

The context

I'm viewing some complex PHP code with a lot of require in it, it is kind of ineffective and time consuming to search for a function's or variable's definition through all the multiple level tree of files included in the current file.

The desired result :

so I'm wondering if a function exists that does the following:

  • Remove all those requires
  • Replace them with their code recursively
  • Output it on the browser or return it to a variable

In a nutshell, a function that prints the final PHP code to be executed.

The question :

Is there such a function? if yes, what is its name?

Thank you for the help.

You cannot get the code which is going to be executed because inclusion of code can be done at run-time, based on variables whose values you don't know before running the code.

What you can do is archive all the possible code to be executed, and pack it up as a phar archive.

Using modern tools, that could mean using composer archive.

More information available here https://getcomposer.org/doc/03-cli.md#archive

Besides, it would go against the ecosystem: in modern PHP applications, you use autoloading. Which means that even in projects with millions of lines of code and hundred of thousands of files, there is only one include/require statement.