summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-08-03 00:55:02 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-08-03 20:09:28 +0200
commit4c89ed61fba666290646af4745435d503352c9d2 (patch)
treeed93f07a394a7359fc2e693e8ca8921b9b0ac612
parent0c238ede019f6ffbe7c996ec1695a747f4bca966 (diff)
downloadphp-git-4c89ed61fba666290646af4745435d503352c9d2.tar.gz
Promote warnings to exceptions in ext/gettext, ext/sysvmsg and ext/xml
Closes GH-5926
-rw-r--r--ext/gettext/gettext.c48
-rw-r--r--ext/gettext/gettext.stub.php18
-rw-r--r--ext/gettext/gettext_arginfo.h22
-rw-r--r--ext/gettext/tests/44938.phpt145
-rw-r--r--ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt15
-rw-r--r--ext/opcache/Optimizer/zend_func_info.c16
-rw-r--r--ext/sysvmsg/sysvmsg.c10
-rw-r--r--ext/sysvmsg/tests/005.phpt16
-rw-r--r--ext/sysvmsg/tests/006.phpt14
-rw-r--r--ext/xml/tests/bug32001b.phpt6
-rw-r--r--ext/xml/tests/xml_parser_get_option_variation4.phpt11
-rw-r--r--ext/xml/tests/xml_parser_set_option_variation4.phpt13
-rw-r--r--ext/xml/tests/xml_parser_set_option_variation5.phpt11
-rw-r--r--ext/xml/xml.c19
-rw-r--r--ext/xml/xml.stub.php6
-rw-r--r--ext/xml/xml_arginfo.h8
16 files changed, 218 insertions, 160 deletions
diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c
index 63131d3360..1395f01fcb 100644
--- a/ext/gettext/gettext.c
+++ b/ext/gettext/gettext.c
@@ -49,16 +49,16 @@ ZEND_GET_MODULE(php_gettext)
#define PHP_GETTEXT_MAX_DOMAIN_LENGTH 1024
#define PHP_GETTEXT_MAX_MSGID_LENGTH 4096
-#define PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len) \
+#define PHP_GETTEXT_DOMAIN_LENGTH_CHECK(_arg_num, domain_len) \
if (UNEXPECTED(domain_len > PHP_GETTEXT_MAX_DOMAIN_LENGTH)) { \
- php_error_docref(NULL, E_WARNING, "Domain passed too long"); \
- RETURN_FALSE; \
+ zend_argument_value_error(_arg_num, "is too long"); \
+ RETURN_THROWS(); \
}
-#define PHP_GETTEXT_LENGTH_CHECK(check_name, check_len) \
+#define PHP_GETTEXT_LENGTH_CHECK(_arg_num, check_len) \
if (UNEXPECTED(check_len > PHP_GETTEXT_MAX_MSGID_LENGTH)) { \
- php_error_docref(NULL, E_WARNING, "%s passed too long", check_name); \
- RETURN_FALSE; \
+ zend_argument_value_error(_arg_num, "is too long"); \
+ RETURN_THROWS(); \
}
PHP_MINFO_FUNCTION(php_gettext)
@@ -78,7 +78,7 @@ PHP_FUNCTION(textdomain)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len)
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
if (domain != NULL && strcmp(domain, "") && strcmp(domain, "0")) {
domain_name = domain;
@@ -102,7 +102,7 @@ PHP_FUNCTION(gettext)
Z_PARAM_STR(msgid)
ZEND_PARSE_PARAMETERS_END();
- PHP_GETTEXT_LENGTH_CHECK("msgid", ZSTR_LEN(msgid))
+ PHP_GETTEXT_LENGTH_CHECK(1, ZSTR_LEN(msgid))
msgstr = gettext(ZSTR_VAL(msgid));
if (msgstr != ZSTR_VAL(msgid)) {
@@ -123,8 +123,8 @@ PHP_FUNCTION(dgettext)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(ZSTR_LEN(domain))
- PHP_GETTEXT_LENGTH_CHECK("msgid", ZSTR_LEN(msgid))
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))
+ PHP_GETTEXT_LENGTH_CHECK(2, ZSTR_LEN(msgid))
msgstr = dgettext(ZSTR_VAL(domain), ZSTR_VAL(msgid));
@@ -147,8 +147,8 @@ PHP_FUNCTION(dcgettext)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(ZSTR_LEN(domain))
- PHP_GETTEXT_LENGTH_CHECK("msgid", ZSTR_LEN(msgid))
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))
+ PHP_GETTEXT_LENGTH_CHECK(2, ZSTR_LEN(msgid))
msgstr = dcgettext(ZSTR_VAL(domain), ZSTR_VAL(msgid), category);
@@ -171,11 +171,11 @@ PHP_FUNCTION(bindtextdomain)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len)
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
if (domain[0] == '\0') {
- php_error(E_WARNING, "The first parameter of bindtextdomain must not be empty");
- RETURN_FALSE;
+ zend_argument_value_error(1, "cannot be empty");
+ RETURN_THROWS();
}
if (dir[0] != '\0' && strcmp(dir, "0")) {
@@ -204,8 +204,8 @@ PHP_FUNCTION(ngettext)
RETURN_THROWS();
}
- PHP_GETTEXT_LENGTH_CHECK("msgid1", msgid1_len)
- PHP_GETTEXT_LENGTH_CHECK("msgid2", msgid2_len)
+ PHP_GETTEXT_LENGTH_CHECK(1, msgid1_len)
+ PHP_GETTEXT_LENGTH_CHECK(2, msgid2_len)
msgstr = ngettext(msgid1, msgid2, count);
@@ -228,9 +228,9 @@ PHP_FUNCTION(dngettext)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len)
- PHP_GETTEXT_LENGTH_CHECK("msgid1", msgid1_len)
- PHP_GETTEXT_LENGTH_CHECK("msgid2", msgid2_len)
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
+ PHP_GETTEXT_LENGTH_CHECK(2, msgid1_len)
+ PHP_GETTEXT_LENGTH_CHECK(3, msgid2_len)
msgstr = dngettext(domain, msgid1, msgid2, count);
@@ -255,9 +255,9 @@ PHP_FUNCTION(dcngettext)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len)
- PHP_GETTEXT_LENGTH_CHECK("msgid1", msgid1_len)
- PHP_GETTEXT_LENGTH_CHECK("msgid2", msgid2_len)
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
+ PHP_GETTEXT_LENGTH_CHECK(2, msgid1_len)
+ PHP_GETTEXT_LENGTH_CHECK(3, msgid2_len)
msgstr = dcngettext(domain, msgid1, msgid2, count, category);
@@ -279,7 +279,7 @@ PHP_FUNCTION(bind_textdomain_codeset)
RETURN_THROWS();
}
- PHP_GETTEXT_DOMAIN_LENGTH_CHECK(domain_len)
+ PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
retval = bind_textdomain_codeset(domain, codeset);
diff --git a/ext/gettext/gettext.stub.php b/ext/gettext/gettext.stub.php
index 6dfb388d59..7e4bec8c9a 100644
--- a/ext/gettext/gettext.stub.php
+++ b/ext/gettext/gettext.stub.php
@@ -2,29 +2,29 @@
/** @generate-function-entries */
-function textdomain(?string $domain): string|false {}
+function textdomain(?string $domain): string {}
-function gettext(string $msgid): string|false {}
+function gettext(string $msgid): string {}
/** @alias gettext */
-function _(string $msgid): string|false {}
+function _(string $msgid): string {}
-function dgettext(string $domain_name, string $msgid): string|false {}
+function dgettext(string $domain, string $msgid): string {}
-function dcgettext(string $domain_name, string $msgid, int $category): string|false {}
+function dcgettext(string $domain, string $msgid, int $category): string {}
-function bindtextdomain(string $domain_name, string $dir): string|false {}
+function bindtextdomain(string $domain, string $dir): string|false {}
#ifdef HAVE_NGETTEXT
-function ngettext(string $msgid1, string $msgid2, int $n): string|false {}
+function ngettext(string $msgid1, string $msgid2, int $n): string {}
#endif
#ifdef HAVE_DNGETTEXT
-function dngettext(string $domain, string $msgid1, string $msgid2, int $count): string|false {}
+function dngettext(string $domain, string $msgid1, string $msgid2, int $count): string {}
#endif
#ifdef HAVE_DCNGETTEXT
-function dcngettext(string $domain, string $msgid1, string $msgid2, int $count, int $category): string|false {}
+function dcngettext(string $domain, string $msgid1, string $msgid2, int $count, int $category): string {}
#endif
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
diff --git a/ext/gettext/gettext_arginfo.h b/ext/gettext/gettext_arginfo.h
index 678fcf704d..b0a8664196 100644
--- a/ext/gettext/gettext_arginfo.h
+++ b/ext/gettext/gettext_arginfo.h
@@ -1,34 +1,34 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 29c84ba2a2aa940baec3bd32503fc7c8e67885fe */
+ * Stub hash: a8b64ae24724f0552a62cd4146f6cfb3cd75fa19 */
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_textdomain, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_textdomain, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 1)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gettext, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gettext, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo__ arginfo_gettext
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_dgettext, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, domain_name, IS_STRING, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dgettext, 0, 2, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid, IS_STRING, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_dcgettext, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, domain_name, IS_STRING, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dcgettext, 0, 3, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, category, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bindtextdomain, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_TYPE_INFO(0, domain_name, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, dir, IS_STRING, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_NGETTEXT)
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ngettext, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ngettext, 0, 3, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, n, IS_LONG, 0)
@@ -36,7 +36,7 @@ ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_DNGETTEXT)
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_dngettext, 0, 4, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dngettext, 0, 4, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid2, IS_STRING, 0)
@@ -45,7 +45,7 @@ ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_DCNGETTEXT)
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_dcngettext, 0, 5, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dcngettext, 0, 5, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, msgid2, IS_STRING, 0)
diff --git a/ext/gettext/tests/44938.phpt b/ext/gettext/tests/44938.phpt
index a5b32c6bf2..4dc45260f8 100644
--- a/ext/gettext/tests/44938.phpt
+++ b/ext/gettext/tests/44938.phpt
@@ -12,71 +12,110 @@ $msgid = "msgid";
$domain = "domain";
$category = "cat";
-var_dump(bindtextdomain($overflown, 'path'));
-
-var_dump(dngettext($overflown, $msgid, $msgid, 1));
-var_dump(dngettext($domain, $overflown, $msgid, 1));
-var_dump(dngettext($domain, $msgid, $overflown, 1));
-
-var_dump(gettext($overflown));
-
-var_dump(ngettext($overflown, $msgid, -1));
-var_dump(ngettext($msgid, $overflown, -1));
-
-var_dump(dcgettext($overflown, $msgid, -1));
-var_dump(dcgettext($domain, $overflown, -1));
-
-var_dump(dcngettext($overflown, $msgid, $msgid, -1, -1));
-var_dump(dcngettext($domain, $overflown, $msgid, -1, -1));
-var_dump(dcngettext($domain, $msgid, $overflown, -1, -1));
-
-var_dump(dgettext($overflown, $msgid));
-var_dump(dgettext($domain, $overflown));
+try {
+ bindtextdomain($overflown, 'path');
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-var_dump(textdomain($overflown));
-?>
---EXPECTF--
-Warning: bindtextdomain(): Domain passed too long in %s on line %d
-bool(false)
+try {
+ dngettext($overflown, $msgid, $msgid, 1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dngettext(): Domain passed too long in %s on line %d
-bool(false)
+try {
+ dngettext($domain, $overflown, $msgid, 1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dngettext(): msgid1 passed too long in %s on line %d
-bool(false)
+try {
+ dngettext($domain, $msgid, $overflown, 1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dngettext(): msgid2 passed too long in %s on line %d
-bool(false)
+try {
+ gettext($overflown);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: gettext(): msgid passed too long in %s on line %d
-bool(false)
+try {
+ ngettext($overflown, $msgid, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: ngettext(): msgid1 passed too long in %s on line %d
-bool(false)
+try {
+ ngettext($msgid, $overflown, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: ngettext(): msgid2 passed too long in %s on line %d
-bool(false)
+try {
+ dcgettext($overflown, $msgid, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dcgettext(): Domain passed too long in %s on line %d
-bool(false)
+try {
+ dcgettext($domain, $overflown, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dcgettext(): msgid passed too long in %s on line %d
-bool(false)
+try {
+ dcngettext($overflown, $msgid, $msgid, -1, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dcngettext(): Domain passed too long in %s on line %d
-bool(false)
+try {
+ dcngettext($domain, $overflown, $msgid, -1, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dcngettext(): msgid1 passed too long in %s on line %d
-bool(false)
+try {
+ dcngettext($domain, $msgid, $overflown, -1, -1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dcngettext(): msgid2 passed too long in %s on line %d
-bool(false)
+try {
+ dgettext($overflown, $msgid);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dgettext(): Domain passed too long in %s on line %d
-bool(false)
+try {
+ dgettext($domain, $overflown);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: dgettext(): msgid passed too long in %s on line %d
-bool(false)
+try {
+ textdomain($overflown);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
-Warning: textdomain(): Domain passed too long in %s on line %d
-bool(false)
+?>
+--EXPECT--
+bindtextdomain(): Argument #1 ($domain) is too long
+dngettext(): Argument #1 ($domain) is too long
+dngettext(): Argument #2 ($msgid1) is too long
+dngettext(): Argument #3 ($msgid2) is too long
+gettext(): Argument #1 ($msgid) is too long
+ngettext(): Argument #1 ($msgid1) is too long
+ngettext(): Argument #2 ($msgid2) is too long
+dcgettext(): Argument #1 ($domain) is too long
+dcgettext(): Argument #2 ($msgid) is too long
+dcngettext(): Argument #1 ($domain) is too long
+dcngettext(): Argument #2 ($msgid1) is too long
+dcngettext(): Argument #3 ($msgid2) is too long
+dgettext(): Argument #1 ($domain) is too long
+dgettext(): Argument #2 ($msgid) is too long
+textdomain(): Argument #1 ($domain) is too long
diff --git a/ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt b/ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt
index 83511d71e2..e900365b52 100644
--- a/ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt
+++ b/ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt
@@ -5,12 +5,21 @@ Test if bindtextdomain() errors if the domain is empty.
if (!extension_loaded("gettext")) {
die("skip gettext extension is not loaded.\n");
}
+?>
--FILE--
<?php
+
chdir(__DIR__);
-bindtextdomain('', 'foobar');
---EXPECTF--
-Warning: The first parameter of bindtextdomain must not be empty in %s on line %d
+
+try {
+ bindtextdomain('', 'foobar');
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
+
+?>
+--EXPECT--
+bindtextdomain(): Argument #1 ($domain) cannot be empty
--CREDITS--
Till Klampaeckel, till@php.net
PHP Testfest Berlin 2009-05-09
diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c
index fb822910a2..47c4af5115 100644
--- a/ext/opcache/Optimizer/zend_func_info.c
+++ b/ext/opcache/Optimizer/zend_func_info.c
@@ -572,7 +572,7 @@ static const func_info_t func_infos[] = {
/* ext/xml */
F1("xml_error_string", MAY_BE_NULL | MAY_BE_STRING),
- F1("xml_parser_get_option", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
+ F1("xml_parser_get_option", MAY_BE_LONG | MAY_BE_STRING),
F1("utf8_encode", MAY_BE_STRING),
F1("utf8_decode", MAY_BE_STRING),
@@ -798,17 +798,17 @@ static const func_info_t func_infos[] = {
F1("filter_list", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
/* ext/gettext */
- F1("textdomain", MAY_BE_FALSE | MAY_BE_STRING),
- F1("gettext", MAY_BE_FALSE | MAY_BE_STRING),
- F1("_", MAY_BE_FALSE | MAY_BE_STRING),
- F1("dgettext", MAY_BE_FALSE | MAY_BE_STRING),
- F1("dcgettext", MAY_BE_FALSE | MAY_BE_STRING),
+ F1("textdomain", MAY_BE_STRING),
+ F1("gettext", MAY_BE_STRING),
+ F1("_", MAY_BE_STRING),
+ F1("dgettext", MAY_BE_STRING),
+ F1("dcgettext", MAY_BE_STRING),
F1("bindtextdomain", MAY_BE_FALSE | MAY_BE_STRING),
#if HAVE_NGETTEXT
- F1("ngettext", MAY_BE_FALSE | MAY_BE_STRING),
+ F1("ngettext", MAY_BE_STRING),
#endif
#if HAVE_DNGETTEXT
- F1("dcngettext", MAY_BE_FALSE | MAY_BE_STRING),
+ F1("dcngettext", MAY_BE_STRING),
#endif
#if HAVE_BIND_TEXTDOMAIN_CODESET
F1("bind_textdomain_codeset", MAY_BE_FALSE | MAY_BE_STRING),
diff --git a/ext/sysvmsg/sysvmsg.c b/ext/sysvmsg/sysvmsg.c
index ff4acd1d6f..c12eaa0674 100644
--- a/ext/sysvmsg/sysvmsg.c
+++ b/ext/sysvmsg/sysvmsg.c
@@ -295,8 +295,8 @@ PHP_FUNCTION(msg_receive)
}
if (maxsize <= 0) {
- php_error_docref(NULL, E_WARNING, "Maximum size of the message has to be greater than zero");
- return;
+ zend_argument_value_error(4, "must be greater than 0");
+ RETURN_THROWS();
}
if (flags != 0) {
@@ -399,7 +399,6 @@ PHP_FUNCTION(msg_send)
p = Z_STRVAL_P(message);
message_len = Z_STRLEN_P(message);
break;
-
case IS_LONG:
message_len = spprintf(&p, 0, ZEND_LONG_FMT, Z_LVAL_P(message));
break;
@@ -412,9 +411,10 @@ PHP_FUNCTION(msg_send)
case IS_DOUBLE:
message_len = spprintf(&p, 0, "%F", Z_DVAL_P(message));
break;
+
default:
- php_error_docref(NULL, E_WARNING, "Message parameter must be either a string or a number.");
- RETURN_FALSE;
+ zend_argument_type_error(3, "must be of type string|int|float|bool, %s given", zend_zval_type_name(message));
+ RETURN_THROWS();
}
messagebuffer = safe_emalloc(message_len, 1, sizeof(struct php_msgbuf));
diff --git a/ext/sysvmsg/tests/005.phpt b/ext/sysvmsg/tests/005.phpt
index 727c42db66..51713e2fab 100644
--- a/ext/sysvmsg/tests/005.phpt
+++ b/ext/sysvmsg/tests/005.phpt
@@ -27,8 +27,12 @@ foreach ($tests as $i => $q) {
var_dump(msg_receive($q, 0, $null, 1, $msg, true, 0, $errno));
var_dump($errno != 0);
- // again, but triggering an E_WARNING
- var_dump(msg_receive($q, 0, $null, 0, $msg));
+ // again, but triggering an exception
+ try {
+ msg_receive($q, 0, $null, 0, $msg);
+ } catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+ }
var_dump(msg_send($q, 1, 'foo', true, true, $errno));
var_dump($errno != 0);
@@ -42,9 +46,7 @@ bool(false)
bool(false)
bool(false)
bool(true)
-
-Warning: msg_receive(): Maximum size of the message has to be greater than zero in %s on line %d
-bool(false)
+msg_receive(): Argument #4 ($maxsize) must be greater than 0
Warning: msg_send(): msgsnd failed: Invalid argument in %s on line %d
bool(false)
@@ -54,9 +56,7 @@ bool(false)
bool(false)
bool(false)
bool(true)
-
-Warning: msg_receive(): Maximum size of the message has to be greater than zero in %s on line %d
-bool(false)
+msg_receive(): Argument #4 ($maxsize) must be greater than 0
Warning: msg_send(): msgsnd failed: Invalid argument in %s on line %d
bool(false)
diff --git a/ext/sysvmsg/tests/006.phpt b/ext/sysvmsg/tests/006.phpt
index fffb684221..479f66cee8 100644
--- a/ext/sysvmsg/tests/006.phpt
+++ b/ext/sysvmsg/tests/006.phpt
@@ -11,7 +11,11 @@ $tests = array('foo', 123, PHP_INT_MAX +1, true, 1.01, null, array('bar'));
foreach ($tests as $elem) {
echo @"Sending/receiving '$elem':\n";
- var_dump(msg_send($queue, 1, $elem, false));
+ try {
+ var_dump(msg_send($queue, 1, $elem, false));
+ } catch (TypeError $exception) {
+ echo $exception->getMessage() . "\n";
+ }
unset($msg);
var_dump(msg_receive($queue, 1, $msg_type, 1024, $msg, false, MSG_IPC_NOWAIT));
@@ -53,16 +57,12 @@ bool(true)
bool(true)
bool(false)
Sending/receiving '':
-
-Warning: msg_send(): Message parameter must be either a string or a number. in %s on line %d
-bool(false)
+msg_send(): Argument #3 ($message) must be of type string|int|float|bool, null given
bool(false)
bool(true)
bool(false)
Sending/receiving 'Array':
-
-Warning: msg_send(): Message parameter must be either a string or a number. in %s on line %d
-bool(false)
+msg_send(): Argument #3 ($message) must be of type string|int|float|bool, array given
bool(false)
bool(false)
bool(false)
diff --git a/ext/xml/tests/bug32001b.phpt b/ext/xml/tests/bug32001b.phpt
index a7762fffca..b88136b973 100644
--- a/ext/xml/tests/bug32001b.phpt
+++ b/ext/xml/tests/bug32001b.phpt
@@ -5,7 +5,11 @@ Bug #32001 (xml_parse*() goes into infinite loop when autodetection in effect),
require_once("skipif.inc");
if (!extension_loaded('iconv')) die ("skip iconv extension not available");
foreach(array('EUC-JP', 'Shift_JISP', 'GB2312') as $encoding) {
- if (@xml_parser_create($encoding) === false) die("skip libxml2 does not support $encoding encoding");
+ try {
+ xml_parser_create($encoding);
+ } catch (ValueError) {
+ die("skip libxml2 does not support $encoding encoding");
+ }
}
?>
--FILE--
diff --git a/ext/xml/tests/xml_parser_get_option_variation4.phpt b/ext/xml/tests/xml_parser_get_option_variation4.phpt
index 9b3c773627..0a1410608b 100644
--- a/ext/xml/tests/xml_parser_get_option_variation4.phpt
+++ b/ext/xml/tests/xml_parser_get_option_variation4.phpt
@@ -11,9 +11,12 @@ if (!extension_loaded('xml')) {
$xmlParser = xml_parser_create();
-var_dump(xml_parser_get_option ($xmlParser, 42));
+try {
+ xml_parser_get_option ($xmlParser, 42);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: xml_parser_get_option(): Unknown option in %s on line %d
-bool(false)
+--EXPECT--
+xml_parser_get_option(): Argument #2 ($option) must be a PHP_XML_OPTION_* constant
diff --git a/ext/xml/tests/xml_parser_set_option_variation4.phpt b/ext/xml/tests/xml_parser_set_option_variation4.phpt
index da59a7eb9b..b1c96b8d33 100644
--- a/ext/xml/tests/xml_parser_set_option_variation4.phpt
+++ b/ext/xml/tests/xml_parser_set_option_variation4.phpt
@@ -15,11 +15,14 @@ if (!extension_loaded("xml")) {
$xmlParser = xml_parser_create();
var_dump(xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, 1));
-var_dump(xml_parser_set_option($xmlParser, XML_OPTION_TARGET_ENCODING, 'Invalid Encoding'));
+
+try {
+ xml_parser_set_option($xmlParser, XML_OPTION_TARGET_ENCODING, 'Invalid Encoding');
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
+--EXPECT--
bool(true)
-
-Warning: xml_parser_set_option(): Unsupported target encoding "Invalid Encoding" in %s on line %d
-bool(false)
+xml_parser_set_option(): Argument #3 ($value) is not a supported target encoding
diff --git a/ext/xml/tests/xml_parser_set_option_variation5.phpt b/ext/xml/tests/xml_parser_set_option_variation5.phpt
index ac6e891072..e637e692a8 100644
--- a/ext/xml/tests/xml_parser_set_option_variation5.phpt
+++ b/ext/xml/tests/xml_parser_set_option_variation5.phpt
@@ -11,9 +11,12 @@ if (!extension_loaded('xml')) {
$xmlParser = xml_parser_create();
-var_dump(xml_parser_set_option($xmlParser, 42, 1));
+try {
+ xml_parser_set_option($xmlParser, 42, 1);
+} catch (ValueError $exception) {
+ echo $exception->getMessage() . "\n";
+}
?>
---EXPECTF--
-Warning: xml_parser_set_option(): Unknown option in %s on line %d
-bool(false)
+--EXPECT--
+xml_parser_set_option(): Argument #2 ($option) must be a PHP_XML_OPTION_* constant
diff --git a/ext/xml/xml.c b/ext/xml/xml.c
index c5d3f71079..c670c2ef52 100644
--- a/ext/xml/xml.c
+++ b/ext/xml/xml.c
@@ -1029,8 +1029,8 @@ static void php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAMETERS, int ns_supp
} else if (strcasecmp(encoding_param, "US-ASCII") == 0) {
encoding = (XML_Char*)"US-ASCII";
} else {
- php_error_docref(NULL, E_WARNING, "Unsupported source encoding \"%s\"", encoding_param);
- RETURN_FALSE;
+ zend_argument_value_error(1, "is not a supported source encoding");
+ RETURN_THROWS();
}
} else {
encoding = XML(default_encoding);
@@ -1442,15 +1442,15 @@ PHP_FUNCTION(xml_parser_set_option)
enc = xml_get_encoding((XML_Char*)Z_STRVAL_P(val));
if (enc == NULL) {
- php_error_docref(NULL, E_WARNING, "Unsupported target encoding \"%s\"", Z_STRVAL_P(val));
- RETURN_FALSE;
+ zend_argument_value_error(3, "is not a supported target encoding");
+ RETURN_THROWS();
}
parser->target_encoding = enc->name;
break;
}
default:
- php_error_docref(NULL, E_WARNING, "Unknown option");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be a PHP_XML_OPTION_* constant");
+ RETURN_THROWS();
break;
}
RETVAL_TRUE;
@@ -1483,12 +1483,9 @@ PHP_FUNCTION(xml_parser_get_option)
RETURN_STRING((char *)parser->target_encoding);
break;
default:
- php_error_docref(NULL, E_WARNING, "Unknown option");
- RETURN_FALSE;
- break;
+ zend_argument_value_error(2, "must be a PHP_XML_OPTION_* constant");
+ RETURN_THROWS();
}
-
- RETVAL_FALSE; /* never reached */
}
/* }}} */
diff --git a/ext/xml/xml.stub.php b/ext/xml/xml.stub.php
index 93d6159891..5f90d91fe4 100644
--- a/ext/xml/xml.stub.php
+++ b/ext/xml/xml.stub.php
@@ -2,9 +2,9 @@
/** @generate-function-entries */
-function xml_parser_create(?string $encoding = null): XmlParser|false {}
+function xml_parser_create(?string $encoding = null): XmlParser {}
-function xml_parser_create_ns(?string $encoding = null, string $sep = ':'): XmlParser|false {}
+function xml_parser_create_ns(?string $encoding = null, string $sep = ':'): XmlParser {}
function xml_set_object(XmlParser $parser, object $obj): bool {}
@@ -61,7 +61,7 @@ function xml_parser_free(XmlParser $parser): bool {}
/** @param string|int $value */
function xml_parser_set_option(XmlParser $parser, int $option, $value): bool {}
-function xml_parser_get_option(XmlParser $parser, int $option): string|int|false {}
+function xml_parser_get_option(XmlParser $parser, int $option): string|int {}
final class XMLParser
{
diff --git a/ext/xml/xml_arginfo.h b/ext/xml/xml_arginfo.h
index c6f21994d4..ea17fca77d 100644
--- a/ext/xml/xml_arginfo.h
+++ b/ext/xml/xml_arginfo.h
@@ -1,11 +1,11 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 60a1f2421a3320374850aa5da7e995077961705e */
+ * Stub hash: b3c718c2aeba9a9c05b6cb281fd7ccaa3791d34e */
-ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xml_parser_create, 0, 0, XmlParser, MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_xml_parser_create, 0, 0, XmlParser, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xml_parser_create_ns, 0, 0, XmlParser, MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_xml_parser_create_ns, 0, 0, XmlParser, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sep, IS_STRING, 0, "\':\'")
ZEND_END_ARG_INFO()
@@ -77,7 +77,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parser_set_option, 0, 3, _IS
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_xml_parser_get_option, 0, 2, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_xml_parser_get_option, 0, 2, MAY_BE_STRING|MAY_BE_LONG)
ZEND_ARG_OBJ_INFO(0, parser, XmlParser, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_END_ARG_INFO()