]> granicus.if.org Git - php/commitdiff
Throw an exception when an invalid comparison operator is passed to version_compare()
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 15 Nov 2019 19:44:23 +0000 (20:44 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 9 Dec 2019 18:44:01 +0000 (19:44 +0100)
ext/opcache/Optimizer/zend_func_info.c
ext/standard/tests/versioning/version_compare_invalid_operator.phpt
ext/standard/versioning.c

index a973efdb72908b1b4fc0b85c88ad40b5e134b24d..fde3a9a91e44f47e11d0b6a825b00a425cf44139 100644 (file)
@@ -503,7 +503,7 @@ static const func_info_t func_infos[] = {
        FN("array_key_last",               MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
        F1("pos",                          UNKNOWN_INFO),
        F1("assert_options",               MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_OBJECT | MAY_BE_OBJECT),
-       F0("version_compare",              MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_LONG),
+       F0("version_compare",              MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_LONG),
        F1("str_rot13",                    MAY_BE_STRING),
        F1("stream_get_filters",           MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
        F0("stream_filter_register",       MAY_BE_FALSE | MAY_BE_TRUE),
index d759422954cec421f95e8524e610fe5af4212428..eb1973924af61331fb42d7a105587fcccae74397 100644 (file)
@@ -1,10 +1,14 @@
 --TEST--
-Ensures null is returned if versions are compared with invalid operator
+Ensures an exception is thrown if versions are compared with an invalid operator
 --CREDITS--
 David Stockton - <dave@davidstockton.com> - i3logix PHP Testfest 2017
 --FILE--
 <?php
-var_dump(version_compare('1.2', '2.1', '??'));
+try {
+    version_compare('1.2', '2.1', '??');
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 ?>
 --EXPECT--
-NULL
+Invalid comparison operator
index c1348239682467cf46cb339c5919d524ec8f54d9..c736c8241f34a06a64a279c8ca986ae0d8f7a592 100644 (file)
@@ -237,7 +237,8 @@ PHP_FUNCTION(version_compare)
        if (!strncmp(op, "!=", op_len) || !strncmp(op, "<>", op_len) || !strncmp(op, "ne", op_len)) {
                RETURN_BOOL(compare != 0);
        }
-       RETURN_NULL();
+
+       zend_value_error("Invalid comparison operator");
 }
 
 /* }}} */