Making stdClass iterable View as Markdown

Declined
Authors
Craig Duncan php@duncanc.co.uk
Date
2019-01-12
Version
0.2
Source
wiki.php.net/rfc/iterable-stdclass

Vote

Making stdClass iterable closed
Yes
7
No
25
32 voters
ajf No 2019-02-06 01:42
andrey No 2019-02-05 19:31
ashnazg No 2019-02-05 21:34
bishop Yes 2019-02-12 14:49
bwoebi Yes 2019-02-13 11:53
carusogabriel No 2019-02-06 09:50
danack No 2019-02-04 19:13
didou No 2019-02-11 11:00
diegopires No 2019-02-05 18:44
duncan3dc Yes 2019-02-08 18:33
emir No 2019-02-17 10:13
galvao Yes 2019-02-08 06:32
girgias No 2019-02-04 19:01
hywan No 2019-02-06 15:33
jhdxr No 2019-02-10 18:01
kalle No 2019-02-04 19:02
kelunik No 2019-02-12 21:10
kguest No 2019-02-05 07:48
krakjoe No 2019-02-04 19:21
levim No 2019-02-04 21:48
lex No 2019-02-11 08:09
nikic Yes 2019-02-10 19:14
ocramius No 2019-02-04 19:01
peehaa No 2019-02-04 23:23
petk No 2019-02-15 22:40
pmmaga No 2019-02-07 10:31
pollita Yes 2019-02-07 00:09
ramsey No 2019-02-08 21:05
salathe No 2019-02-04 19:28
sebastian No 2019-02-05 06:46
stas No 2019-02-04 19:17
trowski Yes 2019-02-07 16:37

Discussions on the mailing list

Making stdClass iterable
by Craig Duncan · 14 messages
[VOTE] Making stdClass iterable
by Craig Duncan · 8 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC

Introduction

By far the most common usage of stdClass is (as the manual defines) “Created by typecasting to object”, or from the result of a call to 'json_decode()' using the default parameters. In both of these scenarios the resulting object is analogous to a plain array. Although it is a class, it has no methods or private/protected properties, it is simply an array that uses a different syntax for accessing its elements.

However the iterable type (introduced in PHP 7.1) does not accept this object, despite accepting the virtually identical array it was born from.

Proposal

This RFC proposes that stdClass is changed to implement the Traversable interface so that code using the iterable type can accept/return these objects.

Backward Incompatible Changes

This RFC aims to be fully backward compatible, although the implementation of the iteration will likely change, all existing behaviour of iterating over stdClass will be retained.

Proposed PHP Version(s)

PHP 7.4

Proposed Voting Choices

Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.

Vote

Vote: Making stdClass iterable — Yes: 7 · No: 25 (closed)

Implementation

An initial proof of concept is available here: https://github.com/php/php-src/pull/3388(note that this implementation is not complete, it still has some edge cases and may change significantly)

References

Discussion thread: https://externals.io/message/103718

Voting thread: https://externals.io/message/104139