|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-10-05 00:42 UTC] aharvey@php.net
-Status: Open
+Status: Bogus
[2011-10-05 00:42 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 01:00:01 2025 UTC |
Description: ------------ Hi there, I want to report that implements native interface for Iterator and ArrayAccess, seriously damage cpu perfomance (compared to native array: absolutely huge). Use my attached-class for testing for 300 array records, then perfomance suffered. Test script: --------------- <?php namespace Entity; abstract class ListArray implements \Iterator, \ArrayAccess, \Countable, \Serializable { private $container = array(); final public function __construct($data = array()) { $this->doConstruct($data); } function __clone() { } protected function doConstruct($data) { $this->container = array_merge((array) $data, $this->container); } function __set($key, $val) { $this->container[$key] = $val; } public function rewind() { reset($this->container); } public function current() { return current($this->container); } public function key() { return key($this->container); } public function next() { next($this->container); } public function valid() { return (key($this->container) !== NULL); } public function offsetGet($offset) { return isset($this->container[$offset])? $this->container[$offset] : NULL; } public function offsetSet($offset, $value) { if(is_null($offset)) { $this->container [] = $value; } else { $this->container [$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function count() { static $count; return ++$count; } public function filter($typ) { $result = array(); $this->rewind(); while($this->valid()) { if(stripos($this->key(), $typ) !== FALSE) $result[$this->key()] = $this->current(); $this->next(); } return $result; } public function serialize() { $props = array(); foreach($this as $key => $val) { $props [$key] = $val; } return serialize(array($this->container, $props)); } public function unserialize($data) { list($this->container, $props) = unserialize($data); foreach($props as $key => $val) { $this->$key = $val; } } } Expected result: ---------------- Significant perfomance like native-array Actual result: -------------- Poor perfomance, absolutely different from native-array