diff options
Diffstat (limited to 'ext/xml')
-rw-r--r-- | ext/xml/tests/bug32001b.phpt | 6 | ||||
-rw-r--r-- | ext/xml/tests/xml_parser_get_option_variation4.phpt | 11 | ||||
-rw-r--r-- | ext/xml/tests/xml_parser_set_option_variation4.phpt | 13 | ||||
-rw-r--r-- | ext/xml/tests/xml_parser_set_option_variation5.phpt | 11 | ||||
-rw-r--r-- | ext/xml/xml.c | 19 | ||||
-rw-r--r-- | ext/xml/xml.stub.php | 6 | ||||
-rw-r--r-- | ext/xml/xml_arginfo.h | 8 |
7 files changed, 42 insertions, 32 deletions
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() |