xref: /PHP-8.0/ext/phar/tests/refcount1.phpt (revision a555cc0b)
1--TEST--
2Phar: test that refcounting avoids problems with deleting a file
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7phar.require_hash=0
8--FILE--
9<?php
10$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
11$pname = 'phar://' . $fname;
12$file = "<?php __HALT_COMPILER(); ?>";
13
14$files = array();
15$files['a.php'] = '<?php echo "This is a\n"; ?>';
16$files['b.php'] = '<?php echo "This is b\n"; ?>';
17$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
18include 'files/phar_test.inc';
19
20$fp = fopen($pname . '/b/c.php', 'wb');
21fwrite($fp, "extra");
22fclose($fp);
23echo "===CLOSE===\n";
24$p = new Phar($fname);
25$b = fopen($pname . '/b/c.php', 'rb');
26$a = $p['b/c.php'];
27var_dump($a);
28var_dump(fread($b, 20));
29rewind($b);
30echo "===UNLINK===\n";
31unlink($pname . '/b/c.php');
32var_dump($a);
33var_dump(fread($b, 20));
34include $pname . '/b/c.php';
35?>
36
37--CLEAN--
38<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
39--EXPECTF--
40===CLOSE===
41object(PharFileInfo)#%d (2) {
42  [%spathName":%sSplFileInfo":private]=>
43  string(%d) "phar://%srefcount1.phar.php/b/c.php"
44  [%sfileName":%sSplFileInfo":private]=>
45  string(%d) "c.php"
46}
47string(5) "extra"
48===UNLINK===
49
50Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.php", has open file pointers, cannot unlink in %srefcount1.php on line %d
51object(PharFileInfo)#%d (2) {
52  [%spathName":%sSplFileInfo":private]=>
53  string(%d) "phar://%srefcount1.phar.php/b/c.php"
54  [%sfileName":%sSplFileInfo":private]=>
55  string(%s) "c.php"
56}
57string(5) "extra"
58extra
59