Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66088 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53776 invoked from network); 21 Feb 2013 06:34:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2013 06:34:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=pencap@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pencap@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.180 as permitted sender) X-PHP-List-Original-Sender: pencap@gmail.com X-Host-Fingerprint: 209.85.210.180 mail-ia0-f180.google.com Received: from [209.85.210.180] ([209.85.210.180:59335] helo=mail-ia0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/77-03224-B00C5215 for ; Thu, 21 Feb 2013 01:34:52 -0500 Received: by mail-ia0-f180.google.com with SMTP id f27so7820594iae.25 for ; Wed, 20 Feb 2013 22:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=tAmFnUOH6RWW3Zf5vi2GaCHL6yPSU9bda6MH9wrkli8=; b=X3pvP9nISUTlUXYVfm+BqhGkimKy1ADNDHiRsVHUYtI/YsC3ZNPhbnsJggXByyqsjV dWr+zEwXzCaU+2fUGWrApivIH7c4hSNfhrXr0uReT7/9PNDI4umppL65or+A3j5dMQRx h48AjGGNbSWPQMlf+rW1jK6/URo69RmuM8NsYqasX622pQfpOfxN2tXPiqgWAvryoajX uU4k4KrOcYgMYVwaDetzBr4lr7uNVqkDTIUE0TSgm2Nn9F74Ctz7A6CvCPgVeo8ZFr1U 0FLAteoat6LhzX5MGwG/DowB+yqFIcWu2ictV1O5lgWIjmQBe1RmFupV4WVoVqbSwG7Q JM0w== MIME-Version: 1.0 X-Received: by 10.50.157.138 with SMTP id wm10mr10209275igb.103.1361428488960; Wed, 20 Feb 2013 22:34:48 -0800 (PST) Received: by 10.50.85.232 with HTTP; Wed, 20 Feb 2013 22:34:48 -0800 (PST) Date: Wed, 20 Feb 2013 22:34:48 -0800 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=e89a8f23593378b9de04d63645e8 Subject: ArrayObject Odd Behavior From: pencap@gmail.com (Mike Willbanks) --e89a8f23593378b9de04d63645e8 Content-Type: text/plain; charset=UTF-8 Hello Again, I wanted to bring back the topic I started on ArrayObject; I've been doing a ton of work with ArrayObject lately and finding some odd behavior. Firstly it would be great to know if these are by design or bugs. Secondly there are some areas where it likely needs to be improved. 1: ArrayObject return by reference: Yes, you can tell offsetGet and __get to return by a reference; however, in the case of multi-dimensional arrays it will not work due to the internal implementation of ArrayObject. Internally it stores everything in a private variable "storage" which is an instance of an ArrayObject. Unfortunately since it is a regular instance of an ArrayObject and not one of the current declarations it will pose issues when attempting to unset variables. Example: class myArrayObject extends ArrayObject { public function &offsetGet($key) { $var =& $this->storage[$key]; return $var; } } $ao = new myArrayObject(array('foo' => array('bar' => 'baz'))); unset($ao['foo']['bar']); PHP Notice: Indirect modification of overloaded element of myArrayObject has no effect 2: ArrayObject and Iterators: For some reason when you do an exchangeArray with an iterator, it basically does a type cast leaving you with an array key of the iterator class name appended with "var". Unfortunately this key is "special" or something because it cannot be accessed, isset returns false but you can get to your records by either foreach or shifting or popping the array. Not really certain if this is intended at all and if so might need to be reworked? Example: var = $array; } } public function rewind() { reset($this->var); } public function current() { return current($this->var); } public function key() { return key($this->var); } public function next() { return next($this->var); } public function valid() { $key = key($this->var); $var = ($key !== NULL && $key !== FALSE); return $var; } } $ao = new ArrayObject(); $mi = new MyIterator(array('foo' => 'bar')); $ao->exchangeArray($mi); $array = $ao->getArrayCopy(); var_dump($array); var_dump(isset($array['MyIteratorvar'])); $params = array_shift($array); var_dump($params); var_dump(isset($params['foo'])); This will output: array(1) { ["MyIteratorvar"]=> array(1) { ["foo"]=> string(3) "bar" } } bool(false) array(1) { ["foo"]=> string(3) "bar" } bool(true) That one had me dumb founded for a while; you can see this behavior just as easy by doing it directly on the iterator itself and type casting it to an array. Example: $ir = new MyIterator(array('foo' => 'bar')); var_dump((array) $ir); Anyhow it would be good to know your thoughts; on these two things. I believe there is a bug ticket already for the first item; the second item I didn't see anything within the first few pages but maybe I'm searching for it without the right keywords. Thanks for listening! --e89a8f23593378b9de04d63645e8--