====== PHP RFC: Making stdClass iterable ====== * Version: 0.2 * Date: 2019-01-12 * Author: Craig Duncan * Proposed version: PHP 7.4 * Status: Declined * ML thread: https://externals.io/message/103718 ===== Introduction ===== By far the most common usage of ''stdClass'' is (as the [[http://php.net/manual/en/reserved.classes.php|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 ===== * Yes * No ===== 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