3v4l.org

run code in 500+ PHP versions simultaneously
<?php $dir = sys_get_temp_dir() . '/decompress-demo-' . getmypid(); mkdir($dir); $archive = new PharData("$dir/my.tar"); $archive['myfile.txt'] = 'hi'; $compressed = $archive->compress(Phar::GZ); // creates my.tar.gz // The default name, my.tar, is taken by the original archive try { $compressed->decompress(); } catch (BadMethodCallException $e) { echo $e->getMessage(), "\n"; } // The copy is written next to my.tar.gz, not in the working directory chdir(sys_get_temp_dir()); $decompressed = $compressed->decompress('decompressed.tar'); var_dump(file_exists("$dir/my.tar.gz"), file_exists("$dir/my.decompressed.tar")); var_dump(file_exists(getcwd() . '/my.decompressed.tar')); var_dump($compressed->isCompressed(), $decompressed->isCompressed());
Output for 8.5.11
Unable to add newly converted phar "/tmp/decompress-demo-2/my.tar" to the list of phars, a phar with that name already exists bool(true) bool(true) bool(false) int(4096) bool(false)

preferences:
166.97 ms | 1519 KiB | 26 Q