1--TEST-- 2Phar: test for the odd case where we intend to remove an archive from memory 3--SKIPIF-- 4<?php if (!extension_loaded("phar")) die("skip"); ?> 5--INI-- 6phar.readonly=0 7--FILE-- 8<?php 9$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php'; 10$pname = 'phar://' . $fname; 11$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.phar.php'; 12$pname2 = 'phar://' . $fname2; 13 14$phar = new Phar($fname); 15$phar->setAlias('first'); 16$phar['file1.txt'] = 'hi'; 17unset($phar); 18 19$phar2 = new Phar($fname2); 20$phar2->setAlias('first'); // this works because there are no references to $fname open 21$phar2['file1.txt'] = 'hi'; 22unset($phar2); 23 24$a = fopen($pname . '/file1.txt', 'r'); // this works because there are no references to $fname2 open 25try { 26$phar2 = new Phar($fname2); // fails because references open to $fname 27} catch (Exception $e) { 28echo $e->getMessage(),"\n"; 29} 30fclose($a); 31$phar2 = new Phar($fname2); // succeeds because all refs are closed 32var_dump($phar2->getAlias()); 33 34$a = file_get_contents($pname . '/file1.txt'); // this fails because $fname2 ref exists 35?> 36===DONE=== 37--CLEAN-- 38<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> 39<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?> 40--EXPECTF-- 41Cannot open archive "%stest_alias_unset.2.phar.php", alias is already in use by existing archive 42string(5) "first" 43 44Warning: file_get_contents(phar://%sfile1.txt): failed to open stream: Cannot open archive "%stest_alias_unset.phar.php", alias is already in use by existing archive in %stest_alias_unset.php on line %d 45===DONE=== 46