Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65698 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54678 invoked from network); 6 Feb 2013 17:10:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2013 17:10:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=sommertm@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sommertm@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.49 as permitted sender) X-PHP-List-Original-Sender: sommertm@gmail.com X-Host-Fingerprint: 209.85.210.49 mail-da0-f49.google.com Received: from [209.85.210.49] ([209.85.210.49:40499] helo=mail-da0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/81-45907-E6E82115 for ; Wed, 06 Feb 2013 12:10:07 -0500 Received: by mail-da0-f49.google.com with SMTP id t11so745478daj.22 for ; Wed, 06 Feb 2013 09:10:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:content-type:mime-version:subject:from:in-reply-to:date :cc:content-transfer-encoding:message-id:references:to:x-mailer; bh=BKmx3JpxBLWNdZSHRF0VHtABs96lKIYQLangtStq/2A=; b=JiekWTTPYaGrCD3p2x36+edF3DU28YiNAYjxXqevObYN4ooQSoxnzjp2es3c8SFFMP hjl3xnjD8eM5sJsR5AhUAhagpO6UzQ3+/dA2Q0QFbaAsPOsBVPMJiix046CzeE2GUqn2 bMuH/9IWRnbmYUR7TzCunvbI/228OahOGsPeel/hi7r1RZkOavrbWPwveKvLFwww0QJE ZI3ZZGVV1gSKDx12sDLsUlsJsZiWSBnC62cnutZtaX01HaugMTFxOfGAb8we1O11BRJ9 Vr42kwGZdgFMlufKv1MLcLnbQH4fHIxajxfyb5gQkcwyJAzFb0ArNl2HDxOnCP2lUnc7 cjZA== X-Received: by 10.66.73.105 with SMTP id k9mr77674199pav.37.1360170603128; Wed, 06 Feb 2013 09:10:03 -0800 (PST) Received: from [192.168.13.232] ([66.202.183.58]) by mx.google.com with ESMTPS id l5sm39125591pax.10.2013.02.06.09.09.53 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 09:10:01 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) In-Reply-To: Date: Wed, 6 Feb 2013 09:09:42 -0800 Cc: Etienne Kneuss , Mike Willbanks , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Anthony Ferrara X-Mailer: Apple Mail (2.1499) Subject: Re: [PHP-DEV] ArrayAccess/ArrayObject return by reference From: sommertm@gmail.com (Tyler Sommer) 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... >=20 > It's perhaps not the cleanest, but it solves the BC issues... >=20 > Anthony >=20 >=20 > On Wed, Feb 6, 2013 at 11:42 AM, Etienne Kneuss = wrote: >=20 >> 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. >>=20 >> Think of all the subclasses that extend ArrayObject who currently do = not do >> that? >>=20 >> Other than that, returning a ref where it previously didn't can have = all >> kinds of undesirable and hard-to-track consequences. >>=20 >> Best, >>=20 >>=20 >> On Wed, Feb 6, 2013 at 4:27 PM, Mike Willbanks = wrote: >>=20 >>> 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? >>>=20 >>> 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. >>>=20 >>> 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 =3D new ArrayObject(array('foo' =3D> array('bar' =3D> = array('baz' =3D> >>> 'foo')))); >>> unset($ar['foo']['bar']['baz']); >>>=20 >>> Regards, >>>=20 >>> Mike >>>=20 >>=20 >>=20 >>=20 >> -- >> Etienne Kneuss >> http://www.colder.ch >>=20