Handle this typehints
[hiphop-php.git] / hphp / test / quick / cgetm_ge.php
blob8a69471e45c2c252fdd950bfeb75288b6ede391d
1 <?hh
3 class ary implements ArrayAccess {
4 private $c;
5 public function __construct($c = 2) {
6 $this->c = $c;
8 public function offsetExists($i) {
9 return true;
11 public function offsetGet($i) {
12 return $i * $this->c;
14 public function offsetSet($i, $v) {
16 public function offsetUnset($i) {
20 function init() {
21 $GLOBALS['gArray'] = array(1, 2, 'bob', 'cat');
22 $GLOBALS['gObj'] = new ary(4);
23 $GLOBALS['gInt'] = 24;
24 $GLOBALS['gStr'] = '01234567890';
27 function main() {
28 var_dump($GLOBALS['gArray'][2]);
29 var_dump($GLOBALS['gObj'][6]);
30 var_dump($GLOBALS['gInt'][1]);
31 var_dump($GLOBALS['gStr'][3]);
33 $idx = array(2, 6, 1, 3);
34 foreach (array('gArray', 'gObj', 'gInt', 'gStr') as $dyn) {
35 var_dump($GLOBALS[$dyn][array_shift($idx)]);
38 init();
39 main();
41 function non_exist() {
42 $a = $GLOBALS['doesnt_exist'][12];
43 var_dump($a);
45 foreach ($GLOBALS as $k => $v) {
46 if ($k == 'doesnt_exist') {
47 echo "has key $k\n";
52 non_exist();