1--TEST--
2Phar: disallow stub and alias setting via offset*() methods
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$phar = new Phar($fname);
15$phar->setDefaultStub();
16$phar->setAlias('susan');
17$phar['a.txt'] = "first file\n";
18$phar['b.txt'] = "second file\n";
19
20try {
21    $phar->offsetGet('.phar/stub.php');
22} catch (Exception $e) {
23    echo $e->getMessage()."\n";
24}
25
26try {
27    $phar->offsetGet('.phar/alias.txt');
28} catch (Exception $e) {
29    echo $e->getMessage()."\n";
30}
31
32try {
33    $phar->offsetSet('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
34} catch (Exception $e) {
35    echo $e->getMessage()."\n";
36}
37
38var_dump(strlen($phar->getStub()));
39
40try {
41    $phar->offsetUnset('.phar/stub.php');
42} catch (Exception $e) {
43    echo $e->getMessage()."\n";
44}
45
46var_dump(strlen($phar->getStub()));
47
48try {
49    $phar->offsetSet('.phar/alias.txt', 'dolly');
50} catch (Exception $e) {
51    echo $e->getMessage()."\n";
52}
53
54var_dump($phar->getAlias());
55
56try {
57    $phar->offsetUnset('.phar/alias.txt');
58} catch (Exception $e) {
59    echo $e->getMessage()."\n";
60}
61
62var_dump($phar->getAlias());
63
64?>
65--CLEAN--
66<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
67--EXPECTF--
68Entry .phar/stub.php does not exist
69Entry .phar/alias.txt does not exist
70Cannot set stub ".phar/stub.php" directly in phar "%sphar_offset_check.phar.php", use setStub
71int(6643)
72int(6643)
73Cannot set alias ".phar/alias.txt" directly in phar "%sphar_offset_check.phar.php", use setAlias
74string(5) "susan"
75string(5) "susan"
76