1--TEST--
2Phar::unlinkArchive()
3--EXTENSIONS--
4phar
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10
11try {
12Phar::unlinkArchive("");
13} catch (Exception $e) {
14echo $e->getMessage(),"\n";
15}
16
17$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
18$pdname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.tar';
19
20try {
21Phar::unlinkArchive($fname);
22} catch (Exception $e) {
23echo $e->getMessage(),"\n";
24}
25file_put_contents($pdname, 'blahblah');
26try {
27Phar::unlinkArchive($pdname);
28} catch (Exception $e) {
29echo $e->getMessage(),"\n";
30}
31try {
32    Phar::unlinkArchive(array());
33} catch (TypeError $e) {
34    echo $e->getMessage(), "\n";
35}
36
37$pname = 'phar://' . $fname;
38$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.zip';
39$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.zip';
40$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>';
41$file = $stub;
42
43$files = array();
44$files['a'] = 'a';
45$files['b'] = 'b';
46$files['c'] = 'c';
47
48include 'files/phar_test.inc';
49
50$phar = new Phar($fname);
51var_dump($phar->isFileFormat(Phar::ZIP));
52var_dump($phar->getStub());
53try {
54Phar::unlinkArchive($fname);
55} catch (Exception $e) {
56echo $e->getMessage(),"\n";
57}
58$phar = $phar->convertToExecutable(Phar::ZIP);
59var_dump($phar->isFileFormat(Phar::ZIP));
60var_dump($phar->getStub());
61
62copy($fname2, $fname3);
63
64$phar = new Phar($fname3);
65var_dump($phar->isFileFormat(Phar::ZIP));
66var_dump($phar->getStub());
67
68Phar::unlinkArchive($fname);
69var_dump(file_exists($fname));
70$phar = new Phar($fname);
71var_dump(count($phar));
72$phar['evil.php'] = '<?php
73try {
74Phar::unlinkArchive(Phar::running(false));
75} catch (Exception $e) {echo $e->getMessage(),"\n";}
76var_dump(Phar::running(false));
77include Phar::running(true) . "/another.php";
78?>';
79$phar['another.php'] = "hi\n";
80unset($phar);
81include $pname . '/evil.php';
82?>
83--CLEAN--
84<?php
85unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
86unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar');
87unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip');
88unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.zip');
89__HALT_COMPILER();
90?>
91--EXPECTF--
92Unknown phar archive ""
93Unknown phar archive "%sphar_unlinkarchive.phar"
94Unknown phar archive "%sphar_unlinkarchive.phar.tar": internal corruption of phar "%sphar_unlinkarchive.phar.tar" (truncated entry)
95Phar::unlinkArchive(): Argument #1 ($filename) must be of type string, array given
96bool(false)
97string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
98phar archive "%sphar_unlinkarchive.phar" has open file handles or objects.  fclose() all file handles, and unset() all objects prior to calling unlinkArchive()
99bool(true)
100string(60) "<?php // zip-based phar archive stub file
101__HALT_COMPILER();"
102bool(true)
103string(60) "<?php // zip-based phar archive stub file
104__HALT_COMPILER();"
105bool(false)
106int(0)
107phar archive "%sphar_unlinkarchive.phar" cannot be unlinked from within itself
108string(%d) "%sphar_unlinkarchive.phar"
109hi
110