Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104470 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7243 invoked from network); 19 Feb 2019 12:53:51 -0000 Received: from unknown (HELO mail-it1-f178.google.com) (209.85.166.178) by pb1.pair.com with SMTP; 19 Feb 2019 12:53:51 -0000 Received: by mail-it1-f178.google.com with SMTP id y184so4597992itc.1 for ; Tue, 19 Feb 2019 01:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3ncY97N9145dyMzYvaHM+X8sw14VyIv2PW1OP+/CfgI=; b=Ce1oIvJOLD+YAzY3/QAJrQLput1Yy59H3yOmLi0hfbTcLYAx++yog5TfAEAO2fnWaK 6K98incVFTNxLjHFDImek6rlijGKpXGtdGh1OzBI4ReHa1da15/MkGXAoqEnUxSXe7+S IDUKzD0IxjIJO/lAYXqxM3kiVOEo79THUifyYFerzJywPr/NxS7Xa/28YqvSJhM+J/Mv 063SOWCHL/Bkm3by6XaEaJnkZkZ1O8KChDYX2MZyR2LCmxMqRYt/RjsLar9YcPMM1nzK y4WtNVaBGc+z+CB+0w0dMFiwJNyy/TJlJCX3xDVKKos+bSVddDPIDk7cD3/bN3FTMwvV zX9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3ncY97N9145dyMzYvaHM+X8sw14VyIv2PW1OP+/CfgI=; b=W0+5Tk7HTRsahE+XJZUvBljn9w12Lq+sfFk9L6vXkT7q0pGmMcepB+msRyx3fQtXZ/ lh7Eynpn1I2B6YM+phnILsIDkaJOIvEsPDtyFkmHDFYhNE9m9kJxJUtQjioLBpRvpZAy ea7zC5ZHE1lLy6oyrNPYNuOSDcFpS4kReMOr6Xk6fYyojDQiL+IPqwLkxMidFTx2x68o d+ZQlDrLWRv43rUZDd5yGjr/08bYwpE6eXAd5nA4p0KaTjDJ0LYNNBkfYlATpai4z+xu uCLiox/FvAcGzf9IBHfs3cC06xMXEGX9vpKJXJ5t5u0Oxt8/dWCWUDEQeNWfA3AC1/w6 Av0w== X-Gm-Message-State: AHQUAuZ1A0SCYQ8/gDTiwgKBqZ4KyPL/28tCAU4VnRLaGTBMouWUQG0E mAFTb73hR5ig8IYE+6ioTOPiArcLEW9Wu8UNWVaGInnn X-Google-Smtp-Source: AHgI3IaPCBiERhrNytTC40+VADYd/LXg5+ums7BEom+TMXNcpk1LasUmamCm13rtF03sid+CtmlSnceOUa+UqX4FcsA= X-Received: by 2002:a6b:7402:: with SMTP id s2mr15107509iog.219.1550569107588; Tue, 19 Feb 2019 01:38:27 -0800 (PST) MIME-Version: 1.0 References: <1838251.7kDW7efa0E@vulcan> <3247148.HBVCQ37Dhl@vulcan> In-Reply-To: <3247148.HBVCQ37Dhl@vulcan> Date: Tue, 19 Feb 2019 09:38:16 +0000 Message-ID: To: Larry Garfield Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000db89d305823c0035" Subject: Re: [PHP-DEV] Allows arrays to be type-hinted with interfaces mimicking Array behaviour From: rowan.collins@gmail.com (Rowan Collins) --000000000000db89d305823c0035 Content-Type: text/plain; charset="UTF-8" On Tue, 19 Feb 2019 at 02:44, Larry Garfield wrote: > Yes, a lot of existing code uses arrays as anonymous structs. Such code > is, > IMO, "doing it wrong". That includes PHP default behavior in many cases. > The > super-globals are one of the exceptions, as since by definition you don't > know > what the keys could be in advance you need some sort of generic accessor. > > superglobals anyway on the grounds that globals are evil (fact check: > true). > There is often an object wrapping around the session that has get() and > set() > object be kind-of-array-ish-for-some-part-of-array-ish-ness is a > long-standing > problem, no question. iterable was a good addition. I think there was > discussion of a countable type hint at one point, but I don't think it > made it > That leaves ArrayAccessible (aka, you can put [] after it and something > useful > happens), which is what you describe. I would not be against adding such > a > instead of an object is Just Plain Wrong(tm). Even a bare public property > class is superior in every possible way, before we even get into questions > of > useful accessor methods. > > be. (Eg, parsing JSON, GET or POST parameters, etc.) > 2) You're being sloppy and not thinking through your API. > struct into an object that has appropriate accessors that can then handle > error cases, missing values, etc. Not doing so results in things like, > say, > particular anonymous-struct was missing a certain key, which I didn't know > was > possible, but it broke the whole application. (Seriously, that was my > entire > struct, even if you're using __get() or ArrayAccerss to do it. (SimpleXML > is > an example of that approach, for better or worse.) > where you have to care, but those are edge-casey. > > ArrayAccessible is a code smell, and the solution is to properly structure > your data and type hint on a defined class instead. Including an > ArrayAccessible pseudo-type would be just a matter of completeness, not > something I would advise anyone actually use. Hi Larry, The above post seems to have been mangled somewhere and lost some of its text. It's mostly readable anyway (and I think I agree with what's there) but if you have a copy of the original anywhere, you might want to re-post it. Regards, -- Rowan Collins [IMSoP] --000000000000db89d305823c0035--