1--TEST-- 2Phar: fopen a .phar for writing (new file) zip-based 3--SKIPIF-- 4<?php 5if (!extension_loaded("phar")) die("skip"); 6?> 7--INI-- 8phar.readonly=0 9phar.require_hash=0 10--FILE-- 11<?php 12 13$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip'; 14$alias = 'phar://' . $fname; 15 16$phar = new Phar($fname); 17$phar->setStub('<?php __HALT_COMPILER(); ?>'); 18 19$files = array(); 20 21$files['a.php'] = '<?php echo "This is a\n"; ?>'; 22$files['b.php'] = '<?php echo "This is b\n"; ?>'; 23$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; 24 25foreach ($files as $n => $file) { 26 $phar[$n] = $file; 27} 28$phar->stopBuffering(); 29 30ini_set('phar.readonly', 1); 31 32function err_handler($errno, $errstr, $errfile, $errline) { 33 echo "Recoverable fatal error: $errstr in $errfile on line $errline\n"; 34} 35 36set_error_handler("err_handler", E_RECOVERABLE_ERROR); 37 38$fp = fopen($alias . '/b/new.php', 'wb'); 39fwrite($fp, 'extra'); 40fclose($fp); 41 42include $alias . '/b/c.php'; 43include $alias . '/b/new.php'; 44?> 45 46===DONE=== 47--CLEAN-- 48<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip'); ?> 49--EXPECTF-- 50Warning: fopen(phar://%sopen_for_write_newfile_b.phar.zip/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 51 52Warning: fwrite() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d 53 54Warning: fclose() expects parameter 1 to be resource, boolean given in %sopen_for_write_newfile_b.php on line %d 55This is b/c 56 57Warning: include(phar://%sopen_for_write_newfile_b.phar.zip/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.zip" in %sopen_for_write_newfile_b.php on line %d 58 59Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.zip/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d 60 61===DONE=== 62