Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65696 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50439 invoked from network); 6 Feb 2013 16:43:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2013 16:43:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.47 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.216.47 mail-qa0-f47.google.com Received: from [209.85.216.47] ([209.85.216.47:59381] helo=mail-qa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/C0-45907-61882115 for ; Wed, 06 Feb 2013 11:43:02 -0500 Received: by mail-qa0-f47.google.com with SMTP id j8so2398097qah.20 for ; Wed, 06 Feb 2013 08:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=jYibIfeZ7HI/D7iZeIhf6JVCJR8oQeXK3Dd54l+E4uM=; b=Ned39mg6IwvWc2I7yW6+9b1jWit+3yp9Q7Zgu80FdyhtCsDrx63UJ4TvanDKP/Mk/7 /721P+44KkB40BosYoc5+3ilQqIgjtQE+AcXGA41vO+xydwdpTliHSxdZd1CrOB4RP9R DCReYquSpQJOy/oGgLiupyDWCpZaVkIt9X7cFeplXQ3gysii0IddbqyBD4MCkGtonXOs WNHDXWafJeE3tkL7w4GV37tNKRMKm8dBs5lmIE+iE7jR/p8NGr0oF3W0+23Gsf7KFRPE 5Mq53Tkzp1/ZxmFGXF2OI125ExbwYAKL8c+UsJR3ruxbm8ERTiPvus5F5jaUy5E+alOv MTzQ== X-Received: by 10.224.42.130 with SMTP id s2mr538727qae.63.1360168979727; Wed, 06 Feb 2013 08:42:59 -0800 (PST) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.49.133.42 with HTTP; Wed, 6 Feb 2013 08:42:39 -0800 (PST) In-Reply-To: References: Date: Wed, 6 Feb 2013 17:42:39 +0100 X-Google-Sender-Auth: RTwz5knOvGCYtF3bW5FTM2w3T9M Message-ID: To: Mike Willbanks Cc: PHP Internals Content-Type: multipart/alternative; boundary=20cf3074d6b4df04a004d5110496 Subject: Re: [PHP-DEV] ArrayAccess/ArrayObject return by reference From: colder@php.net (Etienne Kneuss) --20cf3074d6b4df04a004d5110496 Content-Type: text/plain; charset=UTF-8 I assume it would be possible technically but might break (at least by issuing E_STRICT) a lot of code if we forced ArrayObject::offsetGet to return a reference. Think of all the subclasses that extend ArrayObject who currently do not do that? Other than that, returning a ref where it previously didn't can have all kinds of undesirable and hard-to-track consequences. Best, On Wed, Feb 6, 2013 at 4:27 PM, Mike Willbanks wrote: > Looking at: http://lxr.php.net/xref/PHP_5_5/Zend/zend_interfaces.c#538 it > seems that ArrayAccess at the moment can not be returned by a reference. > I'm wondering if there was a technical reason behind this or if it is now > a BC reason? > > Anyhow; I was attempting to dig through the source code a bit more last > night to see why ArrayObject could not overload the function declaration of > offsetGet to force a return by reference aka: function &offsetGet($key)... > which works now for ArrayAccess but not for ArrayObject. I believe it has > to deal with ArrayObject inheriting ArrayAccess? Is there a way to allow > ArrayObject to change the function declaration in this way? My PHP > internals skills are not the best which is the reason for the question. > > Anyhow; justification wise: in userland this leads to a lot of wtf factor. > It really comes down to having to provide our own implementation of > ArrayObject by extending several different areas including ArrayAccess so > that references can be returned so multi-dimensional arrays can be properly > unset aka: > $ar = new ArrayObject(array('foo' => array('bar' => array('baz' => > 'foo')))); > unset($ar['foo']['bar']['baz']); > > Regards, > > Mike > -- Etienne Kneuss http://www.colder.ch --20cf3074d6b4df04a004d5110496--