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