1--TEST--
2Phar::setStub()/getStub() tar-based
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.require_hash=0
7phar.readonly=0
8--FILE--
9<?php
10
11$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.tar';
12
13$phar = new Phar($fname);
14$stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>' ."\r\n";
15$phar->setStub($stub);
16$phar->setAlias('hio');
17$phar['a'] = 'a';
18$phar->stopBuffering();
19
20var_dump($phar->getStub());
21var_dump($phar->getStub() == $stub);
22
23$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>';
24
25try {
26    $phar->setStub($newstub);
27} catch(exception $e) {
28    echo 'Exception: ' . $e->getMessage() . "\n";
29}
30
31var_dump($phar->getStub());
32var_dump($phar->getStub() == $stub);
33$phar->stopBuffering();
34var_dump($phar->getStub());
35var_dump($phar->getStub() == $stub);
36
37?>
38--CLEAN--
39<?php
40unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
41__HALT_COMPILER();
42?>
43--EXPECTF--
44string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
45"
46bool(true)
47Exception: illegal stub for tar-based phar "%sphar_stub_error.phar.tar"
48string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
49"
50bool(true)
51string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>
52"
53bool(true)
54