Skip to content

Phar Class decompressFiles() bad in PHP 7.4 and 8.x branches #8469

Open
@kwince

Description

@kwince

Description

The following code:

...

<?php
$p = new Phar('/home/gearond/my.phar', FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS, 'my.phar');
$p['myfile.txt'] = 'four score and seven years ago our fathers.';
$p['myfile2.txt'] = 'four score and severn years ago our mothers.';
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump($p->getSupportedCompression() );
var_dump( $p->compressFiles(Phar::GZ) );
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump( $p->decompressFiles() );
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump( $p->extractTo("/home/gearond/Project/exploration", null, true) );
?>

Resulted in this output:

string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
array(1) {
  [0]=>
  string(2) "GZ"
}
NULL
string(10) "myfile.txt"
bool(true)
bool(false)
bool(true)
string(11) "myfile2.txt"
bool(true)
bool(false)
bool(true)
bool(true)
string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
bool(true)

gearond@gearond-XPS-15-9570:~/Project/exploration$ cat *.txt
K�/-R(N�/JUH�KQ(N-K-�S�LM,*VHL�WI��d��K�/-R(N�/JUH�KQ(N-K�S�LM,*VHL�Wɦ%�d��gearond@gearond-XPS-15-9570:~/Project/exploration$ 

But I expected this output instead:

string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
array(1) {
  [0]=>
  string(2) "GZ"
}
NULL
string(10) "myfile.txt"
bool(true)
bool(false)
bool(true)
string(11) "myfile2.txt"
bool(true)
bool(false)
bool(true)
bool(true)
string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
bool(true)
gearond@gearond-XPS-15-9570:~/Project/exploration$ cat *.txt
cat *.txt
four score and severn years ago our mothers.four score and seven years ago our fathers.gearond@gearond-XPS-15-9570:~/Project/exploration$


### PHP Version

php 8.1.2 and 7.4

### Operating System

ubuntu 20.04 and 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions