note 77793 deleted from ref.spl by nlopess

From: Date: Thu, 13 Sep 2007 10:24:16 +0000
Subject: note 77793 deleted from ref.spl by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130455@lists.php.net to get a copy of this message
Note Submitter: prometheus - csaba dot dobai at php-sparcle dot hu ---- This code is an example. By using classes like this, you gives a chance to create classes which extends another class but have most of the ability what a class extends ArrayObject (like multiple inheritance): <?php class foo { public $foo = 'foo'; } // class class foobar extends foo implements ArrayAccess,IteratorAggregate,Countable { public function offsetExists($offset) { $array = array(1, 2, 3, 4); return array_key_exists($offset, $array); } public function offsetGet($offset) { $array = array(1, 2, 3, 4); return $array[$offset]; } public function offsetSet($offset, $value) { // Makes "array" to readonly } public function offsetUnset($offset) { // Makes "array" to readonly } function count() { $array = array(1, 2, 3, 4); return count($array); } // function function getArray() { return array(1, 2, 3, 4); } // function function getIterator() { return new ArrayIterator(array(1, 2, 3, 4)); } // function function __toString() { return 'String test'; } // function } // class $foobar = new foobar(); print $foobar[0].'<br/>'; print $foobar->foo.'<br/>'; print count($foobar).'<br/>'; foreach ($foobar as $k=>$v) { print $k.'=>'.$v.'<br/>'; } // foreach var_dump($foobar->getArray()); print $foobar; /* Generated output: 1 foo 4 foo=>foo array 'foo' => string 'foo' (length=3) String teszt */ ?> For proper use you must be define all these methods except getArray() Browse SPL's sources to be a very helpful think. ps.: sry for my english

« previous php.notes (#130455) next »