]> granicus.if.org Git - php/commitdiff
Promote warnings to exceptions in ext/gettext, ext/sysvmsg and ext/xml
authorMáté Kocsis <kocsismate@woohoolabs.com>
Sun, 2 Aug 2020 22:55:02 +0000 (00:55 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 3 Aug 2020 18:09:28 +0000 (20:09 +0200)
Closes GH-5926

16 files changed:
ext/gettext/gettext.c
ext/gettext/gettext.stub.php
ext/gettext/gettext_arginfo.h
ext/gettext/tests/44938.phpt
ext/gettext/tests/gettext_bindtextdomain-emptydomain.phpt
ext/opcache/Optimizer/zend_func_info.c
ext/sysvmsg/sysvmsg.c
ext/sysvmsg/tests/005.phpt
ext/sysvmsg/tests/006.phpt
ext/xml/tests/bug32001b.phpt
ext/xml/tests/xml_parser_get_option_variation4.phpt
ext/xml/tests/xml_parser_set_option_variation4.phpt
ext/xml/tests/xml_parser_set_option_variation5.phpt
ext/xml/xml.c
ext/xml/xml.stub.php
ext/xml/xml_arginfo.h

index 63131d3360a77a8a670ea59f2e13a883c9e1e9a6..1395f01fcb9c61bd812fd24ab6c0125e277653f6 100644 (file)
@@ -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);
 
index 6dfb388d596cfe771027a79d2ac9cc93af793dc4..7e4bec8c9ac27c76a46ae1a33527ef33c14b9148 100644 (file)
@@ -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
index 678fcf704dccaa064ee7469defa67f3dee311a08..b0a8664196050a8d4d65c3ad6a2e9e6b9ee39ff4 100644 (file)
@@ -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)
index a5b32c6bf2c478642adc697b2657093ac925de6f..4dc45260f8467ae1b61fe516e05e792d4c0a6adc 100644 (file)
@@ -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
index 83511d71e2308941fc4519cc3e4828c36a012bd3..e900365b52d83eb76e373309a25ae272521f83ba 100644 (file)
@@ -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
index fb822910a24d7d4dd76072980b83951685580cca..47c4af5115c45b0d02e06535bd0fbf61c7a12588 100644 (file)
@@ -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),
index ff4acd1d6f160989aa8ce55a66ec2171747aac1f..c12eaa0674824ec315a91aa730dbfd6b9b47732f 100644 (file)
@@ -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));
index 727c42db66bd67c5a910e42c74d926f01a6f1300..51713e2fab1868810e85f29a8e3192ca20242620 100644 (file)
@@ -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)
index fffb684221e44a15920627fe08952dfeedf72242..479f66cee82502160f1097db335d0bce5c7f5b8e 100644 (file)
@@ -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)
index a7762fffca90ecab580a2b457b5614cd296fd72d..b88136b973a9406832982b67d57b0236f8decc9c 100644 (file)
@@ -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--
index 9b3c7736279d045dd0eb3a1a0e70130f65672eb9..0a1410608b4b52c3097c618a1e8637c41b24a637 100644 (file)
@@ -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
index da59a7eb9b6300d8b620010539034c8feb2fd23f..b1c96b8d3326f47634b0dccc8de5cad77aae319a 100644 (file)
@@ -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
index ac6e8910720aad377763c7edcee8ba2ecc45bb3f..e637e692a8d560e45be2791f9fc9fee58910d23b 100644 (file)
@@ -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
index c5d3f71079fa2377fe6245f4dac69188662e0c69..c670c2ef52e12ac173cc7e281811ad6ffac5daac 100644 (file)
@@ -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 */
 }
 /* }}} */
 
index 93d6159891906c7e6e50ce3951799f5e5d0b84e7..5f90d91fe46556b6578b0e0b473c70352dc9d8a6 100644 (file)
@@ -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
 {
index c6f21994d4d89416d9a55114865286f8b84ead90..ea17fca77d8ecc830b4105bc526571816134f2a4 100644 (file)
@@ -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()