Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39567 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6096 invoked from network); 3 Aug 2008 12:20:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Aug 2008 12:20:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:59038] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/38-50899-992A5984 for ; Sun, 03 Aug 2008 08:20:41 -0400 Received: from MBOERGER-ZRH.corp.google.com (194-156.107-92.cust.bluewin.ch [92.107.156.194]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 9D1CF11F9BE; Sun, 3 Aug 2008 14:20:38 +0200 (CEST) Date: Sun, 3 Aug 2008 14:17:51 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <93357385.20080803141751@marcus-boerger.de> To: "Robin Fernandes" CC: internals In-Reply-To: <5a8807d10808030407j14f51cb6ga7d917d51c6206ac@mail.gmail.com> References: <5a8807d10808030407j14f51cb6ga7d917d51c6206ac@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Intended behavior of ArrayObject::exchangeArray() ? From: helly@php.net (Marcus Boerger) Hello Robin, Sunday, August 3, 2008, 1:07:56 PM, you wrote: > Hi all, > I have two questions about the intended behaviour of > ArrayObject::exchangeArray() : > 1. What should happen when the argument is an object? > The docs suggest that the arg should be an array, but the prototype in > the code indicates objects are OK too. However, when an object is > passed, the effect is simply to remove the ArrayObject's storage > container, which doesn't seem right: http://pastebin.ca/1091256 Seems like an error message is missing there. It allows to take an instance of another ArrayObject/Iterator and use the array from that. In case any other Object is passed it is ignored. What do you feel? > 2. Should the ArrayObject store a copy or a real reference to the > array passed to exchangeArray()? > Currently, the ArrayObject container effectively becomes a > copy-on-write reference to the array passed to exchangeArray()... but > there is no logic to split the container when it is modified. > Consequently, the behaviour is very ambiguous: > http://pastebin.ca/1091266 . > Depending on the intended behaviour, it seems either exchangeArray() > needs to take its arg as prefer-by-reference, or the arg needs to be > split before being stashed in the ArrayObject. > One way to address both of these issues is to make exchangeArray() > share the logic that sets the array in __construct(). This way, > echangeArray() works with object arguments (with some special cases if > the argument is itself an ArrayObject), and array arguments are split > before being stored in the ArrayObject. > Here's a suggested patch against 5_3 that implements this (and > includes some tests): http://pastebin.ca/1091668 > Note that I'm not an internals or SPL expert, so let me know if I > missed something. Seems about right. Can you attach the patch as a text file (I cannot open the link). Best regards, Marcus