Edit report at https://bugs.php.net/bug.php?id=61312&edit=1
ID: 61312 Comment by: hanskrentel at yahoo dot de Reported by: le...@php.net Summary: StdClass doesn't implement Traversable but can be traversed. Status: Closed Type: Bug Package: Class/Object related PHP Version: 5.4.0 Block user comment: N Private report: N New Comment: Same for array. It does not "implement" that interface but can be iterated over in a foreach loop. If StdClass *had* the Traverseable interface and foreach would not work, then I'd say this is a bug. See as well the documentation of foreach. If you want to check foreach-ability: check for object or array *not* Traversable. Traversable is an internal type. Previous Comments: ------------------------------------------------------------------------ [2012-03-07 15:26:23] le...@php.net Not a bug, really. All objects can be iterated. I had been up too late when I filed the bug. ------------------------------------------------------------------------ [2012-03-07 07:44:18] le...@php.net Description: ------------ StdClass does not implement the Traversable interface but can be iterated over in a foreach loop. Test script: --------------- $stdClass = new StdClass; $stdClass->setUp = function () { echo "event[setUp] . . . \n"; }; $stdClass->tearDown = function () { echo "event[tearDown] . . . \n"; }; echo "StdClass instanceof Traversable: "; echo $stdClass instanceof Traversable ? "Traversable\n" : "Not traversable\n"; foreach ($stdClass as $key => $value) { echo "$key => "; $value(); } Expected result: ---------------- StdClass instanceof Traversable: Traversable setUp => event[setUp] . . . tearDown => event[tearDown] . . . Actual result: -------------- StdClass instanceof Traversable: Not traversable setUp => event[setUp] . . . tearDown => event[tearDown] . . . ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61312&edit=1