1--TEST--
2Phar: fopen a .phar for writing (new file)
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later");
7?>
8--INI--
9phar.readonly=1
10phar.require_hash=0
11--FILE--
12<?php
13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
14$pname = 'phar://' . $fname;
15$file = "<?php __HALT_COMPILER(); ?>";
16
17$files = array();
18$files['a.php'] = '<?php echo "This is a\n"; ?>';
19$files['b.php'] = '<?php echo "This is b\n"; ?>';
20$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
21include 'files/phar_test.inc';
22
23function err_handler($errno, $errstr, $errfile, $errline) {
24  echo "Catchable fatal error: $errstr in $errfile on line $errline\n";
25}
26
27set_error_handler("err_handler", E_RECOVERABLE_ERROR);
28
29$fp = fopen($pname . '/b/new.php', 'wb');
30fwrite($fp, 'extra');
31fclose($fp);
32include $pname . '/b/c.php';
33include $pname . '/b/new.php';
34?>
35
36===DONE===
37--CLEAN--
38<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
39--EXPECTF--
40
41Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in %sopen_for_write_newfile_b.php on line %d
42
43Warning: fwrite() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d
44
45Warning: fclose() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d
46This is b/c
47
48Warning: include(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line 22
49
50Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.php/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d
51
52===DONE===
53