Skip to content

Commit 0240b90

Browse files
committed
Promote warnings to errors in substr_compare()
1 parent c072ef7 commit 0240b90

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

ext/standard/string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6107,8 +6107,8 @@ PHP_FUNCTION(substr_compare)
61076107
if (len == 0) {
61086108
RETURN_LONG(0L);
61096109
} else {
6110-
php_error_docref(NULL, E_WARNING, "The length must be greater than or equal to zero");
6111-
RETURN_FALSE;
6110+
zend_throw_error(NULL, "The length must be greater than or equal to zero");
6111+
return;
61126112
}
61136113
}
61146114

ext/standard/tests/strings/bug33605.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Bug #33605 (substr_compare crashes)
33
--FILE--
44
<?php
5-
$res = substr_compare("aa", "a", -99999999, -1, 0);
6-
var_dump($res);
5+
try {
6+
substr_compare("aa", "a", -99999999, -1, 0);
7+
} catch (\Error $e) {
8+
echo $e->getMessage();
9+
}
710

811
?>
912
--EXPECTF--
10-
Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
11-
bool(false)
13+
The length must be greater than or equal to zero

ext/standard/tests/strings/substr_compare.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ var_dump(substr_compare("abcde", "abc", 5, 1));
1313
var_dump(substr_compare("abcde", "abcdef", -10, 10) < 0);
1414
var_dump(substr_compare("abcde", "abc", 0, 0));
1515
echo "Test\n";
16-
var_dump(substr_compare("abcde", "abc", 0, -1));
16+
17+
try {
18+
substr_compare("abcde", "abc", 0, -1);
19+
} catch (\Error $e) {
20+
echo $e->getMessage() . "\n";
21+
}
1722
var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0);
1823

1924
echo "Done\n";
@@ -29,8 +34,6 @@ int(-1)
2934
bool(true)
3035
int(0)
3136
Test
32-
33-
Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
34-
bool(false)
37+
The length must be greater than or equal to zero
3538
bool(true)
3639
Done

0 commit comments

Comments
 (0)