Annotation of embedaddon/php/ext/spl/tests/fixedarray_002.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: SPL: FixedArray: overloading
                      3: --FILE--
                      4: <?php
                      5: class A extends SplFixedArray {
                      6:     public function count() {
                      7:         return 2;
                      8:     }
                      9: 
                     10:     public function offsetGet($n) {
                     11:         echo "A::offsetGet\n";
                     12:         return parent::offsetGet($n);
                     13:     }
                     14:     public function offsetSet($n, $v) {
                     15:         echo "A::offsetSet\n";
                     16:         return parent::offsetSet($n, $v);
                     17:     }
                     18:     public function offsetUnset($n) {
                     19:         echo "A::offsetUnset\n";
                     20:         return parent::offsetUnset($n);
                     21:     }
                     22:     public function offsetExists($n) {
                     23:         echo "A::offsetExists\n";
                     24:         return parent::offsetExists($n);
                     25:     }
                     26: }
                     27: 
                     28: $a = new A;
                     29: 
                     30: // errors
                     31: try {
                     32:     $a[0] = "value1";
                     33: } catch (RuntimeException $e) {
                     34:     echo "Exception: ".$e->getMessage()."\n";
                     35: }
                     36: try {
                     37:     var_dump($a["asdf"]);
                     38: } catch (RuntimeException $e) {
                     39:     echo "Exception: ".$e->getMessage()."\n";
                     40: }
                     41: try {
                     42:     unset($a[-1]);
                     43: } catch (RuntimeException $e) {
                     44:     echo "Exception: ".$e->getMessage()."\n";
                     45: }
                     46: $a->setSize(10);
                     47: 
                     48: 
                     49: $a[0] = "value0";
                     50: $a[1] = "value1";
                     51: $a[2] = "value2";
                     52: $a[3] = "value3";
                     53: $ref = "value4";
                     54: $ref2 =&$ref;
                     55: $a[4] = $ref;
                     56: $ref = "value5";
                     57: 
                     58: unset($a[1]);
                     59: var_dump(isset($a[1]), isset($a[2]), empty($a[1]), empty($a[2]));
                     60: 
                     61: var_dump($a[0], $a[2], $a[3], $a[4]);
                     62: 
                     63: // countable
                     64: 
                     65: var_dump(count($a), $a->getSize(), count($a) == $a->getSize());
                     66: ?>
                     67: ===DONE===
                     68: --EXPECTF--
                     69: A::offsetSet
                     70: Exception: Index invalid or out of range
                     71: A::offsetGet
                     72: Exception: Index invalid or out of range
                     73: A::offsetUnset
                     74: Exception: Index invalid or out of range
                     75: A::offsetSet
                     76: A::offsetSet
                     77: A::offsetSet
                     78: A::offsetSet
                     79: A::offsetSet
                     80: A::offsetUnset
                     81: A::offsetExists
                     82: A::offsetExists
                     83: A::offsetExists
                     84: A::offsetExists
                     85: bool(false)
                     86: bool(true)
                     87: bool(true)
                     88: bool(false)
                     89: A::offsetGet
                     90: A::offsetGet
                     91: A::offsetGet
                     92: A::offsetGet
                     93: string(6) "value0"
                     94: string(6) "value2"
                     95: string(6) "value3"
                     96: string(6) "value4"
                     97: int(2)
                     98: int(10)
                     99: bool(false)
                    100: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>