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 = dirname(__FILE__) . '/' . 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===DONE=== 66--CLEAN-- 67<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> 68--EXPECTF-- 69Entry .phar/stub.php does not exist 70Entry .phar/alias.txt does not exist 71Cannot set stub ".phar/stub.php" directly in phar "%sphar_offset_check.phar.php", use setStub 72int(6643) 73int(6643) 74Cannot set alias ".phar/alias.txt" directly in phar "%sphar_offset_check.phar.php", use setAlias 75string(5) "susan" 76string(5) "susan" 77===DONE=== 78