diff options
author | George Peter Banyard <girgias@php.net> | 2020-09-11 18:58:32 +0200 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2020-09-15 12:49:59 +0200 |
commit | b6207338e87a503620e5c98896a2bf9aca517c3f (patch) | |
tree | ee556ed94290d0308358bff9c3d26c568f0da483 | |
parent | 9affbef0e6f13177b46804ec69fd038b07c326f9 (diff) | |
download | php-git-b6207338e87a503620e5c98896a2bf9aca517c3f.tar.gz |
Use normal error in SPL for uninitialized objects
-rw-r--r-- | ext/spl/spl_directory.c | 11 | ||||
-rw-r--r-- | ext/spl/spl_iterators.c | 24 | ||||
-rw-r--r-- | ext/spl/tests/bug54281.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/bug54384.phpt | 34 | ||||
-rw-r--r-- | ext/spl/tests/bug55701.phpt | 12 | ||||
-rw-r--r-- | ext/spl/tests/bug79710.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/iterator_031.phpt | 2 |
7 files changed, 38 insertions, 49 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index b519a610e9..0348a20d34 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -52,10 +52,9 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator; PHPAPI zend_class_entry *spl_ce_SplFileObject; PHPAPI zend_class_entry *spl_ce_SplTempFileObject; -// TODO Use standard Error #define CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(spl_filesystem_object_pointer) \ if (!(spl_filesystem_object_pointer)->u.file.stream) { \ - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); \ + zend_throw_error(NULL, "Object not initialized"); \ RETURN_THROWS(); \ } @@ -209,7 +208,7 @@ static inline int spl_filesystem_object_get_file_name(spl_filesystem_object *int case SPL_FS_INFO: case SPL_FS_FILE: if (!intern->file_name) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); return FAILURE; } break; @@ -1393,9 +1392,7 @@ PHP_METHOD(SplFileInfo, __debugInfo) /* {{{ */ PHP_METHOD(SplFileInfo, _bad_state_ex) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The parent constructor was not called: the object is in an " - "invalid state "); + zend_throw_error(NULL, "The parent constructor was not called: the object is in an invalid state"); } /* }}} */ @@ -2021,7 +2018,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern) /* {{{ */ { if (!intern->u.file.stream) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); + zend_throw_error(NULL, "Object not initialized"); return; } if (-1 == php_stream_rewind(intern->u.file.stream)) { diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 15a9fd7a37..8dfcd84f44 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -125,8 +125,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob do { \ spl_dual_it_object *it = Z_SPLDUAL_IT_P(objzval); \ if (it->dit_type == DIT_Unknown) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ RETURN_THROWS(); \ } \ (var) = it; \ @@ -135,8 +134,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob #define SPL_FETCH_SUB_ELEMENT(var, object, element) \ do { \ if(!(object)->iterators) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ return; \ } \ (var) = (object)->iterators[(object)->level].element; \ @@ -145,8 +143,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob #define SPL_FETCH_SUB_ELEMENT_ADDR(var, object, element) \ do { \ if(!(object)->iterators) { \ - zend_throw_exception_ex(spl_ce_LogicException, 0, \ - "The object is in an invalid state as the parent constructor was not called"); \ + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \ RETURN_THROWS(); \ } \ (var) = &(object)->iterators[(object)->level].element; \ @@ -698,8 +695,7 @@ PHP_METHOD(RecursiveIteratorIterator, getSubIterator) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1059,8 +1055,7 @@ PHP_METHOD(RecursiveTreeIterator, getPrefix) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1092,8 +1087,7 @@ PHP_METHOD(RecursiveTreeIterator, getEntry) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1110,8 +1104,7 @@ PHP_METHOD(RecursiveTreeIterator, getPostfix) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } @@ -1131,8 +1124,7 @@ PHP_METHOD(RecursiveTreeIterator, current) } if(!object->iterators) { - zend_throw_exception_ex(spl_ce_LogicException, 0, - "The object is in an invalid state as the parent constructor was not called"); + zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); RETURN_THROWS(); } diff --git a/ext/spl/tests/bug54281.phpt b/ext/spl/tests/bug54281.phpt index 5d214d9b18..a2dbcd7447 100644 --- a/ext/spl/tests/bug54281.phpt +++ b/ext/spl/tests/bug54281.phpt @@ -12,7 +12,7 @@ foreach($it as $k=>$v) { } ?> --EXPECTF-- -Fatal error: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in %s:%d +Fatal error: Uncaught Error: The object is in an invalid state as the parent constructor was not called in %s:%d Stack trace: #0 %s%ebug54281.php(8): RecursiveIteratorIterator->rewind() #1 {main} diff --git a/ext/spl/tests/bug54384.phpt b/ext/spl/tests/bug54384.phpt index aa2d6fdb93..fa02e372f5 100644 --- a/ext/spl/tests/bug54384.phpt +++ b/ext/spl/tests/bug54384.phpt @@ -7,8 +7,8 @@ function test($f) { try { $f(); echo "ran normally (unexpected)\n\n"; - } catch (LogicException $e) { - echo "exception (expected)\n"; + } catch (\Error $e) { + echo "Error (expected)\n"; } } @@ -154,18 +154,18 @@ echo $a,"\n"; } ); ?> --EXPECT-- -IteratorIterator... exception (expected) -FilterIterator... exception (expected) -RecursiveFilterIterator... exception (expected) -ParentIterator... exception (expected) -LimitIterator... exception (expected) -CachingIterator... exception (expected) -RecursiveCachingIterator... exception (expected) -NoRewindIterator... exception (expected) -RegexIterator... exception (expected) -RecursiveRegexIterator... exception (expected) -GlobIterator... exception (expected) -SplFileObject... exception (expected) -SplTempFileObject... exception (expected) -AppendIterator... exception (expected) -InfiniteIterator... exception (expected) +IteratorIterator... Error (expected) +FilterIterator... Error (expected) +RecursiveFilterIterator... Error (expected) +ParentIterator... Error (expected) +LimitIterator... Error (expected) +CachingIterator... Error (expected) +RecursiveCachingIterator... Error (expected) +NoRewindIterator... Error (expected) +RegexIterator... Error (expected) +RecursiveRegexIterator... Error (expected) +GlobIterator... Error (expected) +SplFileObject... Error (expected) +SplTempFileObject... Error (expected) +AppendIterator... Error (expected) +InfiniteIterator... Error (expected) diff --git a/ext/spl/tests/bug55701.phpt b/ext/spl/tests/bug55701.phpt index 737ebf2184..69b9eb0abb 100644 --- a/ext/spl/tests/bug55701.phpt +++ b/ext/spl/tests/bug55701.phpt @@ -15,7 +15,7 @@ function testBaseClass($f) { } catch (RuntimeException $e) { // Throwing a RuntimeException is the correct behaviour for some methods echo "ran normally (expected)\n"; - } catch (LogicException $e) { + } catch (\Error $e) { // Throwing a LogicException is not correct echo "threw LogicException (unexpected)\n"; } @@ -27,8 +27,8 @@ function testChildClass($f) { try { $f(); echo "didn't throw (unexpected)\n"; - } catch (LogicException $e) { - echo "threw LogicException (expected)\n"; + } catch (\Error $e) { + echo "threw Error (expected)\n"; } catch (Exception $e) { echo "threw other exception (unexpected)\n"; } @@ -330,6 +330,6 @@ non-empty GlobIterator... ran normally (expected) ======================= test there are no regressions ======================= SplFileObject existent file... ran normally (expected) SplFileObject non-existent file... ran normally (expected) -extends GlobIterator... threw LogicException (expected) -extends SplFileObject... threw LogicException (expected) -extends SplTempFileObject... threw LogicException (expected) +extends GlobIterator... threw Error (expected) +extends SplFileObject... threw Error (expected) +extends SplTempFileObject... threw Error (expected) diff --git a/ext/spl/tests/bug79710.phpt b/ext/spl/tests/bug79710.phpt index a5c065fd67..8bfaddb0f8 100644 --- a/ext/spl/tests/bug79710.phpt +++ b/ext/spl/tests/bug79710.phpt @@ -32,7 +32,7 @@ Run::main(); ?> --EXPECTF-- -Fatal error: Uncaught RuntimeException: Object not initialized in %s:%d +Fatal error: Uncaught Error: Object not initialized in %s:%d Stack trace: #0 %s(%d): SplFileObject->flock(2) #1 [internal function]: Target->__destruct() diff --git a/ext/spl/tests/iterator_031.phpt b/ext/spl/tests/iterator_031.phpt index 247e13bfff..d1aed21ac0 100644 --- a/ext/spl/tests/iterator_031.phpt +++ b/ext/spl/tests/iterator_031.phpt @@ -56,7 +56,7 @@ try { $ap->append($it); } -catch(LogicException $e) +catch(\Error $e) { echo $e->getMessage() . "\n"; } |