Created
December 21, 2011 15:40
-
-
Save MidnightLightning/1506458 to your computer and use it in GitHub Desktop.
Phar as an Include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function foobar($msg) { | |
echo "Hello $msg!\n"; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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