Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46580 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99045 invoked from network); 31 Dec 2009 09:35:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2009 09:35:09 -0000 Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.226 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 209.85.219.226 mail-ew0-f226.google.com Received: from [209.85.219.226] ([209.85.219.226:59509] helo=mail-ew0-f226.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/3B-12956-B407C3B4 for ; Thu, 31 Dec 2009 04:35:08 -0500 Received: by ewy26 with SMTP id 26so10092392ewy.23 for ; Thu, 31 Dec 2009 01:35:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=5GPlVTjbbNXy444C2x4lOIafvJS7Mxy11ICpOwF3/So=; b=T+wtCAOavmnQoegQindCKXNi6gbNV/s+794KlSs+9xtI3ECDXTXp/F8DtbfeOcV8bg K50G9OSI6Sgee90bm/7jHdzwZpQfV3MjHqZyiFFp24OhbyXNyi9gaPnVumlVNjAdMpGt YO81JzvU8F2Bc81ik78529vRWHjaD9XNXH5Ds= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=PpJLi+YDqVXgswXMUoB4tVAo+aKzq19wHD70Lq92Nc99T6EXd7QZcDfHgsYgRTM9CZ kcrDMefJfEe+/kGOhPPo4I4L6FjH4h6BIdfhxXN3ST4z4gq1g7BJek87QxmOLVRjvmRw amR/6QY41PspX8gXYTNz3qQ7axy026Tu675KI= MIME-Version: 1.0 Received: by 10.216.89.11 with SMTP id b11mr1340538wef.171.1262252104405; Thu, 31 Dec 2009 01:35:04 -0800 (PST) In-Reply-To: References: <78.83.26502.F1DD83B4@pb1.pair.com> <4B38DDD3.8010108@hexon.cx> <4B394CDC.9040709@warpmail.net> Date: Thu, 31 Dec 2009 10:35:04 +0100 Message-ID: To: Etienne Kneuss Cc: Clint Priest , internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] is_array on objects with ArrayAccess or Iterator implementations From: indeyets@gmail.com (Alexey Zakhlestin) On Tue, Dec 29, 2009 at 3:01 AM, Etienne Kneuss wrote: > Hi, > > On Tue, Dec 29, 2009 at 1:27 AM, Clint Priest wrot= e: >> Etienne Kneuss wrote: >>> >>> On Tue, Dec 29, 2009 at 12:04 AM, Clint Priest >>> wrote: >>>> >>>> Unfortunately $x instanceOf ArrayAccess doesn't return true when $x is >>>> indeed an array. >>> >>> Making is_array return true for objects implementing ArrayAccess is a >>> bad idea, for two main reasons: >>> >>> 1) is_array is a type check, and we should still be able to >>> distinguish real arrays from objects >> >> That's true of course, definitely would need to be able to distinguish. >> >>> 2) ArrayAccess does not guarantee that an object will behave like an >>> array, (e.g. you won't be able to use sort() on an object implementing >>> ArrayAccess. >> >> I wonder if this is something that users would be expecting, that any >> function which took an array would also take an object that implements >> certain interfaces (such as ArrayAccess and perhaps Countable). >> >>> If, in your case, you want to accept both arrays and ArrayAccess >>> objects, I guess if (is_array($v) || $v instanceof ArrayAccess) =C2=A0i= s a >>> sufficiently good way to check. >>> >> >> I'm finding myself implementing ArrayAccess more and more often because = its >> so transparent to the consumer. =C2=A0The reason this came up is because= I was >> considering returning all arrays from a certain section of my shared cod= e >> library always be an array object so that things like >> $tblArray->pluck('Value') could be done, rather than array_pluck() type >> functionality. >> >> That got me to thinking about all of the is_array() calls I would need t= o >> replace throughout the codebase. >> >> Would it be terribly difficult to make objects with ArrayAccess complete= ly >> interchangable anywhere an array element would be required by a function= ? > > Yes, definitely, it would be a quite big amount of work (basically > rewriting every functions dealing with arrays), and the interface that > ArrayAccess proposes isn't enough for most array tasks. can we go other way round and allow to use array's in ArrayAccess context? I'd love to use it as a type-hint. --=20 Alexey Zakhlestin http://www.milkfarmsoft.com/ Sent from Prague, Czech Republic