Skip to content

Instantly share code, notes, and snippets.

@MidnightLightning
Created December 21, 2011 15:40
Show Gist options
  • Save MidnightLightning/1506458 to your computer and use it in GitHub Desktop.
Save MidnightLightning/1506458 to your computer and use it in GitHub Desktop.
Phar as an Include
<?php
function foobar($msg) {
echo "Hello $msg!\n";
return true;
}
<?php
if (!Phar::canWrite()) exit("Not writable!\n");
unlink('lib.phar');
unlink('lib.phar.gz');
$p = new Phar('lib.phar', 0);
$p->addFile('./lib_raw.php', 'lib.php');
$p->compress(Phar::GZ); // Create lib.phar.gz
$p = new Phar('lib.phar.gz', 0);
foreach(new RecursiveIteratorIterator($p) as $file) {
echo $file->getFileName() . "\n";
}
<?php
$path = set_include_path('phar://./lib.phar.gz' . PATH_SEPARATOR . get_include_path());
if ($path === false) exit("Setting include failed\n");
echo get_include_path()."\n";
include("lib.php"); // Pulled out of Phar
foobar("World");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment