1--TEST--
2Phar: disallow stub and alias setting via offset*() methods
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6--INI--
7phar.readonly=0
8phar.require_hash=1
9--FILE--
10<?php
11
12$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
13$pname = 'phar://'.$fname;
14
15$phar = new Phar($fname);
16$phar->setDefaultStub();
17$phar->setAlias('susan');
18$phar['a.txt'] = "first file\n";
19$phar['b.txt'] = "second file\n";
20
21try {
22	$phar->offsetGet('.phar/stub.php');
23} catch (Exception $e) {
24	echo $e->getMessage()."\n";
25}
26
27try {
28	$phar->offsetGet('.phar/alias.txt');
29} catch (Exception $e) {
30	echo $e->getMessage()."\n";
31}
32
33try {
34	$phar->offsetSet('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
35} catch (Exception $e) {
36	echo $e->getMessage()."\n";
37}
38
39var_dump(strlen($phar->getStub()));
40
41try {
42	$phar->offsetUnset('.phar/stub.php');
43} catch (Exception $e) {
44	echo $e->getMessage()."\n";
45}
46
47var_dump(strlen($phar->getStub()));
48
49try {
50	$phar->offsetSet('.phar/alias.txt', 'dolly');
51} catch (Exception $e) {
52	echo $e->getMessage()."\n";
53}
54
55var_dump($phar->getAlias());
56
57try {
58	$phar->offsetUnset('.phar/alias.txt');
59} catch (Exception $e) {
60	echo $e->getMessage()."\n";
61}
62
63var_dump($phar->getAlias());
64
65?>
66===DONE===
67--CLEAN--
68<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
69--EXPECTF--
70Entry .phar/stub.php does not exist
71Entry .phar/alias.txt does not exist
72Cannot set stub ".phar/stub.php" directly in phar "%sphar_offset_check.phar.php", use setStub
73int(6685)
74int(6685)
75Cannot set alias ".phar/alias.txt" directly in phar "%sphar_offset_check.phar.php", use setAlias
76string(5) "susan"
77string(5) "susan"
78===DONE===
79