diff --git a/hphp/runtime/ext/ext_spl.cpp b/hphp/runtime/ext/ext_spl.cpp index 533dc88dc16b6..e48af39c5d6e0 100644 --- a/hphp/runtime/ext/ext_spl.cpp +++ b/hphp/runtime/ext/ext_spl.cpp @@ -227,12 +227,14 @@ Variant f_class_uses(const Variant& obj, bool autoload /* = true */) { return ret; } -Object get_traversable_object_iterator(const Variant& obj) { - if (!obj.isObject() || - !obj.getObjectData()->instanceof(SystemLib::s_TraversableClass)) { - raise_error("Argument must implement interface Traversable"); +#define CHECK_TRAVERSABLE_IMPL(obj, ret) \ + if (!obj.isObject() || \ + !obj.getObjectData()->instanceof(SystemLib::s_TraversableClass)) { \ + raise_recoverable_error("Argument must implement interface Traversable"); \ + return ret; \ } +Object get_traversable_object_iterator(const Variant& obj) { bool isIteratorAggregate; Object itObj = obj.getObjectData() ->iterableObject(isIteratorAggregate, true); @@ -256,6 +258,7 @@ Object get_traversable_object_iterator(const Variant& obj) { Variant f_iterator_apply(const Variant& obj, const Variant& func, const Array& params /* = null_array */) { + CHECK_TRAVERSABLE_IMPL(obj, 0); Object pobj = get_traversable_object_iterator(obj); pobj->o_invoke_few_args(s_rewind, 0); int64_t count = 0; @@ -270,6 +273,7 @@ Variant f_iterator_apply(const Variant& obj, const Variant& func, } Variant f_iterator_count(const Variant& obj) { + CHECK_TRAVERSABLE_IMPL(obj, 0); Object pobj = get_traversable_object_iterator(obj); pobj->o_invoke_few_args(s_rewind, 0); int64_t count = 0; @@ -281,8 +285,9 @@ Variant f_iterator_count(const Variant& obj) { } Variant f_iterator_to_array(const Variant& obj, bool use_keys /* = true */) { - Object pobj = get_traversable_object_iterator(obj); Array ret(Array::Create()); + CHECK_TRAVERSABLE_IMPL(obj, ret); + Object pobj = get_traversable_object_iterator(obj); pobj->o_invoke_few_args(s_rewind, 0); while (same(pobj->o_invoke_few_args(s_valid, 0), true)) { diff --git a/hphp/test/slow/iterator/iterator_to_array.php.expectf b/hphp/test/slow/iterator/iterator_to_array.php.expectf index 4f3c550983a24..0281c270e6439 100644 --- a/hphp/test/slow/iterator/iterator_to_array.php.expectf +++ b/hphp/test/slow/iterator/iterator_to_array.php.expectf @@ -15,4 +15,4 @@ array(3) { int(3) } -Fatal error: Argument must implement interface Traversable in %s/test/slow/iterator/iterator_to_array.php on line 11 +Catchable fatal error: Argument must implement interface Traversable in %s/test/slow/iterator/iterator_to_array.php on line 11 diff --git a/hphp/test/zend/bad/ext/spl/tests/iterator_count.php b/hphp/test/zend/good/ext/spl/tests/iterator_count.php similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/iterator_count.php rename to hphp/test/zend/good/ext/spl/tests/iterator_count.php diff --git a/hphp/test/zend/bad/ext/spl/tests/iterator_count.php.expectf b/hphp/test/zend/good/ext/spl/tests/iterator_count.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/iterator_count.php.expectf rename to hphp/test/zend/good/ext/spl/tests/iterator_count.php.expectf diff --git a/hphp/test/zend/bad/ext/spl/tests/iterator_to_array.php b/hphp/test/zend/good/ext/spl/tests/iterator_to_array.php similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/iterator_to_array.php rename to hphp/test/zend/good/ext/spl/tests/iterator_to_array.php diff --git a/hphp/test/zend/bad/ext/spl/tests/iterator_to_array.php.expectf b/hphp/test/zend/good/ext/spl/tests/iterator_to_array.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext/spl/tests/iterator_to_array.php.expectf rename to hphp/test/zend/good/ext/spl/tests/iterator_to_array.php.expectf