File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / array_access_007.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 4 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    1: --TEST--
    2: ZE2 ArrayAccess and [] assignment
    3: --FILE--
    4: <?php 
    5: 
    6: class OverloadedArray implements ArrayAccess {
    7: 	public $realArray;
    8: 	
    9: 	function __construct() {
   10: 		$this->realArray = array();
   11: 	}
   12: 
   13: 	function offsetExists($index) {
   14: 		return array_key_exists($this->realArray, $index);
   15: 	}
   16: 
   17: 	function offsetGet($index) {
   18: 		return $this->realArray[$index];
   19: 	}
   20: 
   21: 	function offsetSet($index, $value) {
   22: 		if (is_null($index)) {
   23: 			$this->realArray[] = $value;
   24: 		} else {
   25: 			$this->realArray[$index] = $value;
   26: 		}
   27: 	}
   28: 
   29: 	function offsetUnset($index) {
   30: 		unset($this->realArray[$index]);
   31: 	}
   32: 
   33: 	function dump() {
   34: 		var_dump($this->realArray);
   35: 	}
   36: }
   37: 
   38: $a = new OverloadedArray;
   39: $a[] = 1;
   40: $a[1] = 2;
   41: $a[2] = 3;
   42: $a[] = 4;
   43: $a->dump();
   44: ?>
   45: ===DONE===
   46: --EXPECT--
   47: array(4) {
   48:   [0]=>
   49:   int(1)
   50:   [1]=>
   51:   int(2)
   52:   [2]=>
   53:   int(3)
   54:   [3]=>
   55:   int(4)
   56: }
   57: ===DONE===

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