Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104251 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6232 invoked from network); 6 Feb 2019 18:49:32 -0000 Received: from unknown (HELO mail-lf1-f65.google.com) (209.85.167.65) by pb1.pair.com with SMTP; 6 Feb 2019 18:49:32 -0000 Received: by mail-lf1-f65.google.com with SMTP id e27so5639717lfj.8 for ; Wed, 06 Feb 2019 07:30:57 -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=B1CnGeQ9iCXWQbp/wUzeQE8ol0cTRMJoAHhsPX3buuY=; b=bIuFTb9CvCSm1mobqW/QYEErCygWU3k4R6LXBRpZQzM4GrAYXl+RLA0d9ZGo/NOIFi TILjxtrMtsj5Y2YWQwfTMoYut8tnRpkjGNFL+evkkYjGi8H6XKD4XVCM8JFrmafu126r exlMNNFTrc7w2pR+xWOgy+OxxdgJGSwIhjJqHKJGEeIb2GZA3gF0Rc9navo3MtJtgZ+l uCSnJ24Xm7Rs8fdG3gXS8JVFUiAsdVm+1KqiOc1tqz8pZr+MlQKuMbiGCxejW57MN2qY M52FV9f6haonsLQLiqdTGh1JvLa75iAGarrDaskFBCM6EAi0h+esXy4B/2FE986YSnsD VEsQ== 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=B1CnGeQ9iCXWQbp/wUzeQE8ol0cTRMJoAHhsPX3buuY=; b=k2s5GRxAmcdkPJXPD3zVAcv6sGxqshRP03yyfP6jse1Zw+a+44fL3x3hd59sODpQPr FqP+sNzudCgMIcwfvmbTjFPvBCFzqjJ2mGb83Mgl55c+bBD5KQTdX8nJkXlaRRfWq1J4 yYzdP5Y/KUlIj8LhBC5Trc6IZJn5HDP2QW4pIrk41PIGxO8iunmQkdtaSKxHnAfWEd/O 06Hyv4ZgW8AS7TTvhzJxGTGtQYgtWD5V6fKIxN6f2ysliMUCeaP+Sqdp3Ui3FRtB7Ydz 8aL6U8mGwMlwSzn/tOB/ETcVDiTW4QPzAnULMVZJsVJSfoZ+RSRJ3JUTU63UsfyVYlsn okzA== X-Gm-Message-State: AHQUAubHjV1gAUQtTdacTn3lQHDGkLqHhB+sJkaAT9/qvncEkmGwIraO 4VcTtnN/VLM4oex2sb1LYRC0eeyES7GRdSS+DO8= X-Google-Smtp-Source: AHgI3Ia4qKXENShHfVT11UWw0TRJ2thIuiKXe9M+S3rJo3UfMDJT1JaEnJWxe6P7N8HLEjViA+sBXFVeuOW6A5wST9k= X-Received: by 2002:a19:c502:: with SMTP id w2mr6686097lfe.168.1549467056172; Wed, 06 Feb 2019 07:30:56 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Feb 2019 10:30:44 -0500 Message-ID: To: Rowan Collins Cc: Craig Duncan , Internals Content-Type: multipart/alternative; boundary="0000000000007977f105813b6961" Subject: Re: [PHP-DEV] [VOTE] Making stdClass iterable From: chasepeeler@gmail.com (Chase Peeler) --0000000000007977f105813b6961 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 5, 2019 at 1:46 PM Rowan Collins wrote: > On Tue, 5 Feb 2019 at 17:25, Craig Duncan wrote: > > > The *iterable* type accepts a plain array, but not an object that is used > > to represent a plain array, that's surprising to me. > > > > > I think this notion of stdClass as "an object used to represent a plain > array" is a peculiar one. The only reason I can think of for using stdClass > is to specifically *not* be like an array in some way. > > As I mentioned in the discussion thread, the closer comparison would be to > an anonymous class: $foo = new stdClass; and $foo = new class {}; both > produce objects with no behaviour, no pre-defined methods, and the ability > to define properties dynamically. > > In other words, while stdClass CAN represent a plain array in cases where you've casted an array to an object: $c = (object)$array; there is nothing that says ALL instances of stdClass represent a plain array. At the point that the instance isn't representing an array, it's no more iterable than any other class that has properties. You can still iterate the public properties of a class though, even when is_iterable returns false. > On that definition, there's no surprise at all: it's an object that has no > defined behaviour, so is not defined as having the "iterable" behaviour. > > > > > To me, this class is presented as a first class citizen, but it works > like > > a second class one. > > > > > While I agree that it's an anomaly in many ways, I think the fact that it's > not marked iterable is a peculiar detail to get stuck on. > > Regards, > -- > Rowan Collins > [IMSoP] > -- -- Chase chasepeeler@gmail.com --0000000000007977f105813b6961--