I am trying to work out how to interpret PHP's include
construct, e.g. whether it is textual inclusion, when it is evaluated etc. As usual, the documentation is rather informal and vague.
Based on experimentation, it seems to be syntactic sugar. Specifically, the construct
include 'Baz.php'
is an expression which can be replaced with
eval('?>' . file_get_contents('Baz.php', FILE_USE_INCLUDE_PATH))
Is this correct? Is this substitution true in the general case, or just in my tests?
Edit: as bwoebi notes, this is not generally true since the eval
uated code does not have the same __DIR__
and __FILE__
magic constants. If there were some way to set them, we could model that too.
Edit 2: this question is a duplicate of this one: Equivalent of include using eval. However, all the answers there appear to omit bwoebi's point about the file path context.