Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103727 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92822 invoked from network); 14 Jan 2019 15:21:49 -0000 Received: from unknown (HELO mail-it1-f180.google.com) (209.85.166.180) by pb1.pair.com with SMTP; 14 Jan 2019 15:21:49 -0000 Received: by mail-it1-f180.google.com with SMTP id i145so12589715ita.4 for ; Mon, 14 Jan 2019 03:57:26 -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=6fNdvvCCSi+XiGVzrf+XfwEPkFePbtQfuUfGbi6s1yQ=; b=fErgqVk+MsqYCUwJCSaQysvqV2B45uHVEh2kgKBVYU6kU5bz3SG9SvxWHSpY3R43wo MUFjBR+tY85vZGxKwAMd6lve4Jr3DaP+tY/QmkB6NwS78ndLSDYTiOn8bZXJOnYb0mra kNXvMfegbf0Jckv6eILsmC+okcuEQ8JMegqWDmCfAq1Z9cW4ceNKx5SsYC9qgI4K/zb4 A8gPn8RgN2CxyCSQa19xptJjxokT9rvoo/0z2Ijw8MrtLz9mJiy03vkS5roMhUGzAM0x NS04VW0htn5s9GHUdpt9iBoG8j3Ljh0bs2zNtvFhzQ2yVoe8vJYlIiffFe7ckxzvx+4O KgFA== 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=6fNdvvCCSi+XiGVzrf+XfwEPkFePbtQfuUfGbi6s1yQ=; b=A2EPDz0zCxzqQa1Tfqi8nIBpGljboH/aYHORY1KSXo2RiE9iULlRvz6ZC9oJz5A3FM hi1mFRQMWYcSGoVyzm9CqY9tyS3ARDuvaqJXBuB1LmrY79pXlXMXLObQgfIVCNeGbfbU sC7Mx7rrySXN+A3wzfqX3On6yZ0BlLH2o3qQAVzWG3S08NnAJ9h16qRYh9f5Q0ezfLoY 3QhhRTC8CKt1dKTUIIanaJYIbqL+QU0TP9xb1p5Tsc+ihOt2klUlNHGBw0LgWiGBqfNN aHsKW4AjRUHQTPgwhGh7bX/SvdgTXtnk4pR8hLcK+Wzwi0aXISlIHZk6avAs9nktQliJ AK1g== X-Gm-Message-State: AJcUukeS8L7FyQ5leJtCJ6FvWQsYfZUqLp+MXfYR0uQPcugCpVA8hKaJ 4VDsY4hVheORurss+Ln7oPdzyzmBswWteplbHtfR7w== X-Google-Smtp-Source: ALg8bN4jHT4AD0OUDPf8uuqhzHgEF31biG4DiM3yxbxZZeyeDFiIN5rDm+BJfEs9h5R44iIX/4wddYPonjHyWA6zrkc= X-Received: by 2002:a05:660c:74b:: with SMTP id a11mr7567653itl.27.1547467045915; Mon, 14 Jan 2019 03:57:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 14 Jan 2019 12:57:06 +0100 Message-ID: To: Craig Duncan Cc: Internals Content-Type: multipart/alternative; boundary="00000000000092d083057f69bf91" Subject: Re: [PHP-DEV] Making stdClass iterable From: nikita.ppv@gmail.com (Nikita Popov) --00000000000092d083057f69bf91 Content-Type: text/plain; charset="UTF-8" On Sat, Jan 12, 2019 at 8:39 PM Craig Duncan wrote: > Hi everybody > > I'd like to propose a change to stdClass so that it can satisfy the > iterable parameter/return type. > > Firstly I acknowledge that this isn't an ideal solution, but I think it > gets us to a better state than we're in today. It shouldn't be necessary, > but while we have such a common function (json_decode) returning stdClass > we should make it easy/unsurprising to work with. > > https://wiki.php.net/rfc/iterable-stdclass > > Thanks, Craig > Rather than implementing Traversable, I think it would be much better to implement IteratorAggregate and provide a proper getIterator() implementation. Objects that only implement Traversable are a PITA to work with and lots of code assumes that anything Traversable will either be Iterator or IteratorAggregate. For userland code this is strictly enforced, but internal code can avoid this. However, the current exceptions to this are rather niche, while stdClass is somewhat commonly used. I'm in favor of the general change here. What I mainly have in mind is that we should stop allowing iteration over arbitrary objects in the future (we did the first step by excluding them from "iterable") and instead require the use of an explicit PropertyIterator, or similar. However, we'd probably still want to allow direct iteration of stdClass and the cleanest way to do that is to make it Traversable (via IteratorAggregate). Nikita --00000000000092d083057f69bf91--