cvs: ZendEngine2(PHP_5_0) / ZEND_CHANGES

From: Date: Mon, 30 Aug 2004 18:49:49 +0000
Subject: cvs: ZendEngine2(PHP_5_0) / ZEND_CHANGES
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2926@lists.php.net to get a copy of this message
helly Mon Aug 30 14:49:49 2004 EDT Modified files: (Branch: PHP_5_0) /ZendEngine2 ZEND_CHANGES Log: MFH: Add some information about array overloading http://cvs.php.net/diff.php/ZendEngine2/ZEND_CHANGES?r1=1.82.2.1&r2=1.82.2.2&ty=u Index: ZendEngine2/ZEND_CHANGES diff -u ZendEngine2/ZEND_CHANGES:1.82.2.1 ZendEngine2/ZEND_CHANGES:1.82.2.2 --- ZendEngine2/ZEND_CHANGES:1.82.2.1 Tue Aug 3 13:10:58 2004 +++ ZendEngine2/ZEND_CHANGES Mon Aug 30 14:49:49 2004 @@ -890,6 +890,47 @@ the use of all abstract methods declared in the interfaces Iterator and IteratorAggregate respectively. + * Array overloading + + Objects can be used with Array notation when they implement the + interface ArrayAccess. You cannot use such objects in standard + array functions, however you have full control over the array + notation. This allows lazy initialization or read only array. + + Note that setting [] results in a call to offsetSet() with + index being NULL. That means that as with standard arrays you + cannot store NULL keys. + + Example: + + <?php + class ArrayClass implements ArrayAccess { + public $a = array(); + + function offsetExists($index) { + return array_key_exists($index, $this->a); + } + function offsetGet($index) { + return $this->a[$index]; + } + function offsetSet($index, $newval) { + return $this->a[$index] = $newval; + } + function offsetUnset($index) { + unset($this->a[$index]); + } + } + + $obj = new ArrayClass; + + $obj[0] = 'bla'; // calls offsetSet(0,'bla') + $obj[] = 42; // calls offsetSet(NULL, 42) + $x = $obj[0]; // calls offsetGet(0) + $b = isset($obj[0]); // calls offsetExists(0) + unset($obj[0]); // calls offsetUnset(0) + ?> + + * __METHOD__ The pseudo constant __METHOD__ shows the current class and method

« previous php.zend-engine.cvs (#2926) next »