HomePhabricator

Make Phobject detect iteration of non-iterable objects

Description

Make Phobject detect iteration of non-iterable objects

Summary:
See D8914 and IRC. The root issue was that this code:

foreach ($some_object as $thing) {
  // ...
}

...means "iterate over the public properties of the object" in PHP, and does not raise any warnings or throw an exception.

This has very nearly bitten me several times too; we never want to do this. Instead, throw from objects extending Phobject.

Test Plan:

  • Added and ran unit tests.
  • Tried to foreach() an arbitrary object.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D8915

Details

Provenance
epriestleyAuthored on
epriestleyPushed on Apr 30 2014, 6:38 PM
Reviewer
btrahan
Differential Revision
D8915: Make Phobject detect iteration of non-iterable objects
Parents
rPHU1490f4fa10c8: Make PhutilGitURI and PhutilURI strict about leading whitespace
Branches
Unknown
Tags
Unknown

Event Timeline