From 83f80e81618c51deaf0a379253f0ac8da85c9a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 18 Aug 2020 14:29:30 +0200 Subject: [PATCH] Promote warnings to exceptions in ext/pspell --- ext/pspell/pspell.c | 8 ++++---- ext/pspell/tests/003.phpt | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 6712784b3141a..ce3242007e2f0 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -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); diff --git a/ext/pspell/tests/003.phpt b/ext/pspell/tests/003.phpt index 4fc34bf6bd88f..e8677ae82687d 100644 --- a/ext/pspell/tests/003.phpt +++ b/ext/pspell/tests/003.phpt @@ -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)