1--TEST--
2Bug #71317: regression in opening tar based phar files
3--SKIPIF--
4<?php if (!extension_loaded('phar')) die('skip'); ?>
5<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
6--FILE--
7<?php
8include __DIR__ . '/files/tarmaker.php.inc';
9
10$testDirectory = __DIR__ . '/files/test_bug71317';
11$testTarFilename  = __DIR__ . '/files/test_bug71317.tar';
12
13$tar = new tarmaker($testTarFilename, 'none');
14$tar->init();
15$tar->addFile('file1.txt', 'file1');
16$tar->addFile('file2.txt', 'file2');
17$tar->addFile('file3.txt', 'file3');
18$tar->addFile('file4.txt', 'file4');
19$tar->addFile('file5.txt', 'file5');
20$tar->addFile('file2.txt', 'file2a');
21$tar->close();
22
23$fname = str_replace('\\', '/', $testTarFilename);
24try {
25    mkdir($testDirectory);
26    $tar = new PharData($fname);
27    $tar->extractTo($testDirectory);
28
29    $fileContent = file_get_contents($testDirectory . '/file2.txt');
30    $expectedContent = 'file2a';
31    if ($fileContent !== $expectedContent) {
32        throw new Exception(sprintf('Contents of file2.txt ("%s") is invalid, expected "%s"', $fileContent, $expectedContent));
33    }
34} catch(Exception $e) {
35    echo $e->getMessage() . "\n";
36}
37?>
38===DONE===
39--CLEAN--
40<?php
41$testDirectory = __DIR__ . '/files/test_bug71317';
42$testTarFilename  = __DIR__ . '/files/test_bug71317.tar';
43
44unlink($testTarFilename);
45array_map('unlink', glob($testDirectory . "/*.txt"));
46rmdir($testDirectory);
47?>
48--EXPECT--
49===DONE===
50