1

Is there a way to print full php (in php) code after includes and requires?

For example I have 3 files.

File basic.php

<?php echo 2; include 'basic2.php'; ?>

File basic2.php

<?php echo 3; ?>

and the main file main_file.php

<?php echo 1; include 'basic.php'; echo 4; ?>

I would like to get the full code that would be about to be compiled, the result would be something like this:

<?php echo 1; ?><?php echo 2; ?><?php echo 3; ?><?php echo 4; ?>

Is that possible?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Grego
  • 2,220
  • 9
  • 43
  • 64
  • I don't see a way to do this. The `php` command has an option to display the source with syntax highlighting, and an option to display it with comments and excess whitespace removed, but I don't see an option to display it with include files merged. – Barmar Sep 11 '14 at 15:27
  • @Barmar is right. You misunderstood Fred – Grego Sep 11 '14 at 15:28
  • 1
    A problem with trying to do this is that it may have to execute the script to get the include files, because the filenames don't have to be literals. – Barmar Sep 11 '14 at 15:28
  • That's a good point @Fred-ii, but in my case my includes are always literal, I'm trying to make a single file with all the content. – Grego Sep 11 '14 at 15:31
  • Maybe you can find a 3rd-party tool that does it. It might be part of a PHP cross-reference package, or some PHP IDE. Try asking on [Software Recommendation](http://meta.softwarerecs.stackexchange.com/questions/336/what-is-required-for-a-question-to-contain-enough-information) – Barmar Sep 11 '14 at 15:33
  • 1
    @Barmar: that's correct. Even if the filenames are literals, `require/include` statements are processed *during execution*, not at *parse time*. For normal code like `echo 1`, the parser generates instructions for the Zend VM to output the number 1, but `require` instructs the VM to "load this file and parse it" - at the moment `main_file.php` is fully parsed and the VM starts executing it, it still doesn't know anything about the contents of `basic.php`. See [demo on 3v4l](http://3v4l.org/ijb3c/vld#tabs). – DCoder Sep 11 '14 at 15:47

0 Answers0