1<?php
2
3$fname = dirname(__FILE__) . '/write6.phar';
4@unlink($fname);
5
6$phar = new Phar($fname);
7$phar->setStub('<?php
8$phar = new Phar(__FILE__);
9$d = dirname(__FILE__) . "/copyonwrite6";
10mkdir($d);
11file_put_contents($d . "/file1", "file1\n");
12file_put_contents($d . "/file2", "file2\n");
13$arr = $phar->buildFromIterator(new RecursiveDirectoryIterator($d, RecursiveDirectoryIterator::SKIP_DOTS),$d);
14$arr = $phar->buildFromDirectory($d);
15ksort($arr);
16var_dump($arr);
17$phar2 = new Phar(__FILE__);
18$arr = array();
19foreach ($phar2 as $name => $file) {
20    $arr[$name] = $file->getContent();
21}
22ksort($arr);
23foreach ($arr as $name => $content) {
24    echo $name, " ", $content;
25}
26echo "ok\n";
27__HALT_COMPILER();
28?>');
29$phar['hi'] = "hi\n";
30?>
31