]> granicus.if.org Git - php/commitdiff
Use normal error in SPL for uninitialized objects
authorGeorge Peter Banyard <girgias@php.net>
Fri, 11 Sep 2020 16:58:32 +0000 (18:58 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 15 Sep 2020 10:49:59 +0000 (12:49 +0200)
ext/spl/spl_directory.c
ext/spl/spl_iterators.c
ext/spl/tests/bug54281.phpt
ext/spl/tests/bug54384.phpt
ext/spl/tests/bug55701.phpt
ext/spl/tests/bug79710.phpt
ext/spl/tests/iterator_031.phpt

index b519a610e98d67245718911f919d6e0d0993b1d3..0348a20d3451612707b89c6441388cd9b21a7eb9 100644 (file)
@@ -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)) {
index 15a9fd7a37cf485e9212881be1252c1a78815db9..8dfcd84f4422c32c797b8fb33d610ed55387bbd4 100644 (file)
@@ -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();
        }
 
index 5d214d9b18b3aca41e2e20c74cfc951b5e2f62f7..a2dbcd74476f0b2478b113058f6bcfc17210f303 100644 (file)
@@ -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}
index aa2d6fdb93b8aeb2e8af230b939c61dfda305a58..fa02e372f524d20e79d55d8fa1d6a65e2109b83d 100644 (file)
@@ -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)
index 737ebf2184b520087ca6a75a6921b969cd295fbb..69b9eb0abb38481c492c87b4f612d7c4bf5780f5 100644 (file)
@@ -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)
index a5c065fd67ba6308ceb29bbc5e62dc1e93a316fc..8bfaddb0f8c888c8899a504b8605923359be761d 100644 (file)
@@ -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()
index 247e13bfff08add9f4b6c6f0dd701b676ec2fa92..d1aed21ac06921aa20c21a1e9b2d0d12ea291b15 100644 (file)
@@ -56,7 +56,7 @@ try
 {
     $ap->append($it);
 }
-catch(LogicException $e)
+catch(\Error $e)
 {
     echo $e->getMessage() . "\n";
 }