Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65699 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56182 invoked from network); 6 Feb 2013 17:15:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2013 17:15:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:35691] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A3/E1-45907-7BF82115 for ; Wed, 06 Feb 2013 12:15:36 -0500 Received: by mail-vc0-f170.google.com with SMTP id p16so1017587vcq.29 for ; Wed, 06 Feb 2013 09:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=Z5h8y5+zBRki9TswABq/FPH5jKF3WPMVo+bvAwZrLJc=; b=etNngSpKzhIPaIUg8Sd199L3YPlFnJmdRyDqFg/piYTcIx7Weil5isEc/9o41Q/TM8 /GNVwbToHxsAmTRkfuTAq/9WG0wPUaShiwmu7H9lM1px8TjCbAtS5e4S7x9tn4SnW7LF G5Tm6NbnepNQXWIFqJOxYG8UvEfW96rXh3cgaic3ukQjS3F9+uJNG9DgQ5M1Bae4OBGm /Fu802fz+zXvz99OkXIxhVJ6k1GI8n48xFVa59KCzKGqHCU7nokELEBugzGvPWR7HtBO oCZHu9J0R3NDf6f+RUonPRXbloEjSkh6668TojEpYnAiPkQNYpFhGNyeSftUsumuqSL9 nWhQ== MIME-Version: 1.0 X-Received: by 10.220.142.71 with SMTP id p7mr25617519vcu.3.1360170933259; Wed, 06 Feb 2013 09:15:33 -0800 (PST) Received: by 10.58.56.137 with HTTP; Wed, 6 Feb 2013 09:15:33 -0800 (PST) In-Reply-To: References: Date: Wed, 6 Feb 2013 12:15:33 -0500 Message-ID: To: Tyler Sommer Cc: Etienne Kneuss , Mike Willbanks , PHP Internals Content-Type: multipart/alternative; boundary=f46d0434bf0c4f8ec304d511797d Subject: Re: [PHP-DEV] ArrayAccess/ArrayObject return by reference From: ircmaxell@gmail.com (Anthony Ferrara) --f46d0434bf0c4f8ec304d511797d Content-Type: text/plain; charset=ISO-8859-1 Tyler, References are indicated by the function signature, so: interface ArrayAccessReference { public function &offsetGet($key); public function offsetSet($key, $value); public function offsetIsset($key); public function offsetUnset($key); } On Wed, Feb 6, 2013 at 12:09 PM, Tyler Sommer wrote: > How would the interface enforce returning a reference? > > > On Feb 6, 2013, at 8:47 AM, Anthony Ferrara wrote: > > > Perhaps there's another way out of this. A simple way would be to > introduce > > an ArrayAccessReference interface in core that adds the references to the > > getters/setters... > > > > It's perhaps not the cleanest, but it solves the BC issues... > > > > Anthony > > > > > > On Wed, Feb 6, 2013 at 11:42 AM, Etienne Kneuss wrote: > > > >> 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#538it > >>> 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 > >> > > --f46d0434bf0c4f8ec304d511797d--