I kindly need a clarification on php phar file management as on documentation I did not find what expected.
More in deep I have a simple project like this
[main.php]
<?
include_once("./helloworld.php");
helloworld();
?>
[helloworld.php]
<?
function helloworld() {
echo "Hello World\n";
}
?>
Then I've create a phar file with such script:
[buildphar.php]
<?
$pharfile = '/home/stefano/test.phar';
if (file_exists($pharfile)) unlink($pharfile);
$phar = new Phar(
$pharfile,
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
"test.phar"
);
$phar->startBuffering();
$phar['main.php'] = php_strip_whitespace("main.php");
$phar['helloworld.php'] = php_strip_whitespace("helloworls.php");
$phar->setStub($phar->createDefaultStub("main"));
$phar->stopBuffering();
If I distribute [buildphar.php] to another machine and I try to run it
php buildphar.php
The error given is "Fatal error: function 'helloworld' not found in phar://(...)" and so the question is: - How can I mantain include_once('helloword.php') but remove them from phar file knowing that's function is embedded on phar file and does not need to be included? - What's wrong on my approach?
Thanks anyone. Stefano
The code you give does not work. Also, distributing
buildphar.php
does not make sense - you probably mean you distribute the.phar
file.The problem you're facing (includes do not work) can be solved with
Phar::interceptFileFuncs()
in the phar stub.