Homec4science

Make Phobject detect iteration of non-iterable objects

Authored by epriestley <git@epriestley.com> on Apr 30 2014, 20:38.

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

Committed
epriestley <git@epriestley.com>Apr 30 2014, 20:38
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU1490f4fa10c8: Make PhutilGitURI and PhutilURI strict about leading whitespace
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHU3e7297e073e0: Make Phobject detect iteration of non-iterable objects (authored by epriestley <git@epriestley.com>).Apr 30 2014, 20:38