File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / classes / array_access_008.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, 6 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 ASSIGN_OP operators (.=) 
    3: --FILE--
    4: <?php 
    5: 
    6: class Peoples implements ArrayAccess {
    7: 	public $person;
    8: 	
    9: 	function __construct() {
   10: 		$this->person = array(array('name'=>'Foo'));
   11: 	}
   12: 
   13: 	function offsetExists($index) {
   14: 		return array_key_exists($this->person, $index);
   15: 	}
   16: 
   17: 	function offsetGet($index) {
   18: 		return $this->person[$index];
   19: 	}
   20: 
   21: 	function offsetSet($index, $value) {
   22: 		$this->person[$index] = $value;
   23: 	}
   24: 
   25: 	function offsetUnset($index) {
   26: 		unset($this->person[$index]);
   27: 	}
   28: }
   29: 
   30: $people = new Peoples;
   31: 
   32: var_dump($people->person[0]['name']);
   33: $people->person[0]['name'] = $people->person[0]['name'] . 'Bar';
   34: var_dump($people->person[0]['name']);
   35: $people->person[0]['name'] .= 'Baz';
   36: var_dump($people->person[0]['name']);
   37: 
   38: echo "===ArrayOverloading===\n";
   39: 
   40: $people = new Peoples;
   41: 
   42: var_dump($people[0]['name']);
   43: $people[0]['name'] = 'FooBar';
   44: var_dump($people[0]['name']);
   45: $people[0]['name'] = $people->person[0]['name'] . 'Bar';
   46: var_dump($people[0]['name']);
   47: $people[0]['name'] .= 'Baz';
   48: var_dump($people[0]['name']);
   49: 
   50: ?>
   51: ===DONE===
   52: --EXPECTF--
   53: string(3) "Foo"
   54: string(6) "FooBar"
   55: string(9) "FooBarBaz"
   56: ===ArrayOverloading===
   57: string(3) "Foo"
   58: 
   59: Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 40
   60: string(3) "Foo"
   61: 
   62: Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 42
   63: string(3) "Foo"
   64: 
   65: Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 44
   66: string(3) "Foo"
   67: ===DONE===

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