I'm trying to compile some bits of a PHP application into bytecode. The code makes use of the magic constant __FILE__.
infile.php:
<?php
echo dirname(__FILE__);
squish.php:
<?php
$h = fopen('/tmp/pants/outfile.php', 'w');
bcompiler_write_header($h);
bcompiler_write_file($h, '/tmp/trousers/infile.php');
bcompiler_write_footer($h);
fclose($h);
test.php:
<?php
require('/tmp/pants/outfile.php');
开发者_运维知识库
The output of running test.php is /tmp/trousers
rather than /tmp/pants
. I am guessing this is because the bytecode compilation phase translates the magic constants to their respective values before writing the bytecode to the output file, however this severely limits my ability to use the magic constants for anything useful if they will always be tied to the location of the input file.
Are there any other ways to retrieve the name of the current source file? Are there any other techniques which might mitigate the need for __FILE__ but still allow me to refer to paths relative to a given source file?
The problem you are seeing is a bug that has been fixed already, see http://pecl.php.net/bugs/bug.php?id=5693
精彩评论