Page MenuHomePhabricator

Make Phobject detect iteration of non-iterable objects
ClosedPublic

Authored by epriestley on Apr 30 2014, 6:32 PM.
Tags
None
Referenced Files
F15517515: D8915.diff
Sat, Apr 19, 3:33 AM
F15479417: D8915.id.diff
Tue, Apr 8, 7:02 AM
F15419295: D8915.id21150.diff
Mar 21 2025, 5:06 AM
F15414720: D8915.id21151.diff
Mar 20 2025, 2:08 AM
F15413517: D8915.id21152.diff
Mar 19 2025, 7:26 PM
F15413442: D8915.id21152.diff
Mar 19 2025, 6:46 PM
F15410599: D8915.diff
Mar 19 2025, 7:41 AM
F15410464: D8915.id21152.diff
Mar 19 2025, 7:26 AM
Subscribers
Tokens
"Doubloon" token, awarded by btrahan.

Details

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.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

epriestley retitled this revision from to Make Phboject detect iteration of non-iterable objects.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: btrahan.
epriestley retitled this revision from Make Phboject detect iteration of non-iterable objects to Make Phobject detect iteration of non-iterable objects.Apr 30 2014, 6:32 PM
btrahan edited edge metadata.
This revision is now accepted and ready to land.Apr 30 2014, 6:34 PM

Thank goodness we have libphutil and friends! =D

epriestley edited edge metadata.
  • Fix comment to read "Iterator" instead of "Iterable".
  • I ran arc unit --everything everywhere (couple of unrelated minor issues in libphutil) to try to catch class hierarchy issues.
  • I grepped for Iterator. We define a few in libphutil, but none of them currently extend Phobject.
epriestley updated this revision to Diff 21152.

Closed by commit rPHU3e7297e073e0 (authored by @epriestley).