If the code is the same, there appears to be a difference between:
include \'external.php\';
and
eval(\'?>\' . file_get_conten
As noted by @bwoebi in this answer to my question, the eval
substitution does not respect the file path context of the included file. As a test case:
Baz.php
:
Foo.php
:
' . file_get_contents('Baz.php', FILE_USE_INCLUDE_PATH)) . "\n";
echo (include 'Baz.php') . "\n";
Result of executing php Foo.php
:
$ php Foo.php
/path/to/file/Foo.php(2) : eval()'d code
/path/to/file/Baz.php
I don't know of any way to change the __FILE__
constant and friends at runtime, so I do not think there is any general way to define include
in terms of eval
.