From 9affbef0e6f13177b46804ec69fd038b07c326f9 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 11 Sep 2020 18:35:50 +0200 Subject: [PATCH] Use normal error in SPL for 'An iterator cannot be used with foreach by reference' --- ext/spl/spl_array.c | 2 +- ext/spl/spl_directory.c | 4 ++-- ext/spl/spl_dllist.c | 2 +- ext/spl/spl_fixedarray.c | 2 +- ext/spl/spl_heap.c | 4 ++-- ext/spl/spl_iterators.c | 2 +- ext/spl/tests/DirectoryIterator_by_reference.phpt | 2 +- ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt | 2 +- ext/spl/tests/array_019.phpt | 2 +- ext/spl/tests/fixedarray_021.phpt | 2 +- ext/spl/tests/heap_009.phpt | 2 +- ext/spl/tests/iterator_069.phpt | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index ce468267d0..fb23939ca2 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1144,7 +1144,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object, spl_array_object *array_object = Z_SPLARRAY_P(object); if (by_ref && (array_object->ar_flags & SPL_ARRAY_OVERLOADED_CURRENT)) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 72fb1cbe8f..b519a610e9 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1612,7 +1612,7 @@ zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval spl_filesystem_object *dir_object; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } dir_object = Z_SPLFILESYSTEM_P(object); @@ -1819,7 +1819,7 @@ zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zva spl_filesystem_object *dir_object; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } dir_object = Z_SPLFILESYSTEM_P(object); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index eb01c09d80..c576104139 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -1308,7 +1308,7 @@ zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 558514eec1..df20a2b4bf 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -955,7 +955,7 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob spl_fixedarray_it *iterator; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 0beea11da0..ba1b0fd681 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -1066,7 +1066,7 @@ zend_object_iterator *spl_heap_get_iterator(zend_class_entry *ce, zval *object, spl_heap_object *heap_object = Z_SPLHEAP_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } @@ -1091,7 +1091,7 @@ zend_object_iterator *spl_pqueue_get_iterator(zend_class_entry *ce, zval *object spl_heap_object *heap_object = Z_SPLHEAP_P(object); if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index d245cc3567..15a9fd7a37 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -448,7 +448,7 @@ static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, spl_recursive_it_object *object; if (by_ref) { - zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); + zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); return NULL; } iterator = emalloc(sizeof(spl_recursive_it_iterator)); diff --git a/ext/spl/tests/DirectoryIterator_by_reference.phpt b/ext/spl/tests/DirectoryIterator_by_reference.phpt index 0f28262190..a6af6569c9 100644 --- a/ext/spl/tests/DirectoryIterator_by_reference.phpt +++ b/ext/spl/tests/DirectoryIterator_by_reference.phpt @@ -11,7 +11,7 @@ foreach( $it as &$file ) { } ?> --EXPECTF-- -Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d +Fatal error: Uncaught Error: An iterator cannot be used with foreach by reference in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt b/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt index 8c3aad3ef7..769136c406 100644 --- a/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt +++ b/ext/spl/tests/SPLDoublyLinkedList_iterate_by_reference.phpt @@ -17,7 +17,7 @@ try { $value *= $value; echo $value, PHP_EOL; } -} catch (Exception $e) { +} catch (\Error $e) { echo $e->getMessage(), PHP_EOL; } diff --git a/ext/spl/tests/array_019.phpt b/ext/spl/tests/array_019.phpt index 2a86e70589..7d1239c0bd 100644 --- a/ext/spl/tests/array_019.phpt +++ b/ext/spl/tests/array_019.phpt @@ -26,7 +26,7 @@ int(2) int(3) int(4) -Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d +Fatal error: Uncaught Error: An iterator cannot be used with foreach by reference in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/ext/spl/tests/fixedarray_021.phpt b/ext/spl/tests/fixedarray_021.phpt index db4962ef48..6dc26da396 100644 --- a/ext/spl/tests/fixedarray_021.phpt +++ b/ext/spl/tests/fixedarray_021.phpt @@ -46,7 +46,7 @@ try { foreach ($e as $k=>&$v) { var_dump($v); } -} catch (Exception $e) { +} catch (\Error $e) { var_dump($e->getMessage()); } diff --git a/ext/spl/tests/heap_009.phpt b/ext/spl/tests/heap_009.phpt index 39d0a19f4b..833d079b25 100644 --- a/ext/spl/tests/heap_009.phpt +++ b/ext/spl/tests/heap_009.phpt @@ -11,7 +11,7 @@ function testForException( $heap ) { foreach( $heap as &$item ); } - catch( RuntimeException $e ) + catch( \Error $e ) { echo $e->getMessage(),"\n"; } diff --git a/ext/spl/tests/iterator_069.phpt b/ext/spl/tests/iterator_069.phpt index 975fbe2f8e..b9ee3f4b82 100644 --- a/ext/spl/tests/iterator_069.phpt +++ b/ext/spl/tests/iterator_069.phpt @@ -14,7 +14,7 @@ foreach ($recItIt as &$val) echo "$val\n"; ?> --EXPECTF-- -Fatal error: Uncaught RuntimeException: An iterator cannot be used with foreach by reference in %s:%d +Fatal error: Uncaught Error: An iterator cannot be used with foreach by reference in %s:%d Stack trace: #0 {main} thrown in %s on line %d -- 2.40.0