]> granicus.if.org Git - php/commitdiff
Promote warnings to errors in substr_compare()
authorGeorge Peter Banyard <girgias@php.net>
Thu, 22 Aug 2019 09:48:21 +0000 (11:48 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Sat, 31 Aug 2019 21:34:24 +0000 (23:34 +0200)
ext/standard/string.c
ext/standard/tests/strings/bug33605.phpt
ext/standard/tests/strings/substr_compare.phpt

index e9a584aa29034613d937cfdf6873cb26e370c27e..6a1da25d31594c06c167704604b62e94bc3cabba 100644 (file)
@@ -6107,8 +6107,8 @@ PHP_FUNCTION(substr_compare)
                if (len == 0) {
                        RETURN_LONG(0L);
                } else {
-                       php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero");
-                       RETURN_FALSE;
+                       zend_throw_error(NULL, "The length must be greater than or equal to zero");
+                       return;
                }
        }
 
index 7ba38f94f50d27e34b11772c9e9e28ec6bcc67f5..b3cb2ece957cbd0b911eacb14203d3059020e3c5 100644 (file)
@@ -2,10 +2,12 @@
 Bug #33605 (substr_compare crashes)
 --FILE--
 <?php
-$res = substr_compare("aa", "a", -99999999, -1, 0);
-var_dump($res);
+try {
+    substr_compare("aa", "a", -99999999, -1, 0);
+} catch (\Error $e) {
+    echo $e->getMessage();
+}
 
 ?>
 --EXPECTF--
-Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
-bool(false)
+The length must be greater than or equal to zero
index 9d4bac4ba9938dff209609e7fb739c7bda3b9ae8..b0a8a5b0eb509ece493087d9d52e68a3e7db8ee7 100644 (file)
@@ -13,7 +13,12 @@ var_dump(substr_compare("abcde", "abc", 5, 1));
 var_dump(substr_compare("abcde", "abcdef", -10, 10) < 0);
 var_dump(substr_compare("abcde", "abc", 0, 0));
 echo "Test\n";
-var_dump(substr_compare("abcde", "abc", 0, -1));
+
+try {
+    substr_compare("abcde", "abc", 0, -1);
+} catch (\Error $e) {
+    echo $e->getMessage() . "\n";
+}
 var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0);
 
 echo "Done\n";
@@ -29,8 +34,6 @@ int(-1)
 bool(true)
 int(0)
 Test
-
-Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
-bool(false)
+The length must be greater than or equal to zero
 bool(true)
 Done