1--TEST--
2Phar: create and modify phar
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7phar.require_hash=1
8--FILE--
9<?php
10
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
12$pname = 'phar://' . $fname;
13
14@unlink($fname);
15
16file_put_contents($pname . '/a.php', "brand new!\n");
17
18$phar = new Phar($fname);
19$sig1 = $phar->getSignature();
20
21include $pname . '/a.php';
22
23if (function_exists("opcache_get_status")) {
24    $status = opcache_get_status();
25    if (is_array($status) && ($status["opcache_enabled"] || (isset($status["file_cache_only"]) && $status["file_cache_only"]))) {
26        opcache_invalidate($pname . '/a.php', true);
27        // opcache_invalidate is buggy and doesn't work as expected so we add a
28        // minor delay here.
29        sleep(2);
30    }
31}
32
33file_put_contents($pname .'/a.php', "modified!\n");
34file_put_contents($pname .'/b.php', "another!\n");
35
36$phar = new Phar($fname);
37$sig2 = $phar->getSignature();
38
39var_dump($sig1['hash']);
40var_dump($sig2['hash']);
41var_dump($sig1['hash'] != $sig2['hash']);
42
43include $pname . '/a.php';
44include $pname . '/b.php';
45
46?>
47===DONE===
48--CLEAN--
49<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
50--EXPECTF--
51brand new!
52string(40) "%s"
53string(40) "%s"
54bool(true)
55modified!
56another!
57===DONE===
58