1--TEST--
2Phar: fopen a .phar for writing (existing file) tar-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?>
6--INI--
7phar.readonly=0
8phar.require_hash=0
9--FILE--
10<?php
11
12$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
13$alias = 'phar://' . $fname;
14
15$phar = new Phar($fname);
16$phar->setStub("<?php __HALT_COMPILER(); ?>");
17
18$files = array();
19
20$files['a.php'] = '<?php echo "This is a\n"; ?>';
21$files['b.php'] = '<?php echo "This is b\n"; ?>';
22$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
23
24foreach ($files as $n => $file) {
25	$phar[$n] = $file;
26}
27
28$phar->stopBuffering();
29ini_set('phar.readonly', 1);
30
31$fp = fopen($alias . '/b/c.php', 'wb');
32fwrite($fp, b'extra');
33fclose($fp);
34
35include $alias . '/b/c.php';
36
37?>
38
39===DONE===
40--CLEAN--
41<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
42--EXPECTF--
43Warning: fopen(phar://%sopen_for_write_existing_c_5_2.phar.tar/b/c.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_existing_c_5_2.php on line %d
44
45Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c_5_2.php on line %d
46
47Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c_5_2.php on line %d
48This is b/c
49
50===DONE===
51