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