]> granicus.if.org Git - php/commitdiff
Promote warnings to exceptions in ext/pspell
authorMáté Kocsis <kocsismate@woohoolabs.com>
Tue, 18 Aug 2020 12:29:30 +0000 (14:29 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Tue, 18 Aug 2020 17:24:18 +0000 (19:24 +0200)
Closes GH-6010

ext/pspell/pspell.c
ext/pspell/tests/003.phpt

index 6712784b3141ade859be573c3cc2a76618c4f8e7..ce3242007e2f08f08249af4ed37306a35ca715da 100644 (file)
@@ -76,8 +76,8 @@ static void php_pspell_close_config(zend_resource *rsrc)
 #define PSPELL_FETCH_CONFIG  do { \
        zval *res = zend_hash_index_find(&EG(regular_list), conf); \
        if (res == NULL || Z_RES_P(res)->type != le_pspell_config) { \
-               php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " is not a PSPELL config index", conf); \
-               RETURN_FALSE; \
+               zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL config index", get_active_function_name(), conf); \
+               RETURN_THROWS(); \
        } \
        config = (PspellConfig *)Z_RES_P(res)->ptr; \
 } while (0)
@@ -85,8 +85,8 @@ static void php_pspell_close_config(zend_resource *rsrc)
 #define PSPELL_FETCH_MANAGER do { \
        zval *res = zend_hash_index_find(&EG(regular_list), scin); \
        if (res == NULL || Z_RES_P(res)->type != le_pspell) { \
-               php_error_docref(NULL, E_WARNING, ZEND_LONG_FMT " is not a PSPELL result index", scin); \
-               RETURN_FALSE; \
+               zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL result index", get_active_function_name(), scin); \
+               RETURN_THROWS(); \
        } \
        manager = (PspellManager *)Z_RES_P(res)->ptr; \
 } while (0);
index 4fc34bf6bd88fff0a28fa9986fd9c5894fa5a656..e8677ae82687d3797c39a90a25c8b9f3ff18eaa1 100644 (file)
@@ -15,7 +15,11 @@ $p = pspell_new_config($cfg);
 var_dump(pspell_check($p, 'yy'));
 
 $p2 = pspell_new_config($cfg2);
-var_dump(pspell_check($p2, 'yy'));
+try {
+    pspell_check($p2, 'yy');
+} catch (Error $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 echo "---\n";
 var_dump(pspell_config_ignore($cfg, 2));
@@ -30,9 +34,7 @@ var_dump(pspell_config_ignore($cfg, PHP_INT_MAX));
 bool(false)
 
 Warning: pspell_new_config(): PSPELL couldn't open the dictionary. reason: The encoding "b0rked" is not known. This could also mean that the file "%sb0rked.%s" could not be opened for reading or does not exist. in %s003.php on line 9
-
-Warning: pspell_check(): 0 is not a PSPELL result index in %s003.php on line 10
-bool(false)
+pspell_check(): 0 is not a PSPELL result index
 ---
 bool(true)
 bool(true)