0

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?

cweiske
  • 30,033
  • 14
  • 133
  • 194
Shabbyrobe
  • 12,298
  • 15
  • 60
  • 87

1 Answers1

1

The problem you are seeing is a bug that has been fixed already, see http://pecl.php.net/bugs/bug.php?id=5693

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • Thanks for the heads up. I've since well and truly abandoned bcompiler as I could not get it to work at all with a reasonably uncomplicated set of PHP classes on Ubuntu 10.04 or 10.10 with either the latest PECL beta or the latest SVN. It kept giving me method not found errors for classes that extended other classes. – Shabbyrobe Apr 06 '11 at 01:28