1
0
mirror of https://github.com/php/php-src.git synced 2026-04-19 22:11:12 +02:00

Promote warnings to exceptions in string search related functions

GH-5004
This commit is contained in:
Máté Kocsis
2019-11-20 02:34:52 +01:00
parent 17598d503d
commit f3d5a5a9d3
15 changed files with 256 additions and 235 deletions

View File

@@ -30,7 +30,11 @@ foreach ($offsets as $i) {
echo "mb_strrpos:\n";
var_dump(mb_strrpos('This is na English ta', 'a', $i));
echo "strrpos:\n";
var_dump(strrpos('This is na English ta', 'a', $i));
try {
var_dump(strrpos('This is na English ta', 'a', $i));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
}
?>
--EXPECTF--
@@ -45,9 +49,7 @@ mb_strrpos:
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
strrpos:
Warning: strrpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
-- Offset is -24 --
Multibyte String:
@@ -60,9 +62,7 @@ mb_strrpos:
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
bool(false)
strrpos:
Warning: strrpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
-- Offset is -13 --
Multibyte String:

View File

@@ -10,7 +10,11 @@ function section($func, $haystack, $needle)
echo "\n------- $func -----------\n\n";
foreach(array(0, 3, 6, 9, 11, 12, -1, -3, -6, -20) as $offset) {
echo "> Offset: $offset\n";
var_dump($func($haystack,$needle,$offset));
try {
var_dump($func($haystack,$needle,$offset));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
}
}
@@ -40,9 +44,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
> Offset: -1
bool(false)
> Offset: -3
@@ -50,9 +52,7 @@ int(8)
> Offset: -6
int(8)
> Offset: -20
Warning: strpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
------- mb_strpos -----------
@@ -94,9 +94,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
> Offset: -1
bool(false)
> Offset: -3
@@ -104,9 +102,7 @@ int(8)
> Offset: -6
int(8)
> Offset: -20
Warning: stripos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
------- mb_stripos -----------
@@ -148,9 +144,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
Warning: strrpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
> Offset: -1
int(8)
> Offset: -3
@@ -158,9 +152,7 @@ int(8)
> Offset: -6
int(4)
> Offset: -20
Warning: strrpos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
------- mb_strrpos -----------
@@ -202,9 +194,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
Warning: strripos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
> Offset: -1
int(8)
> Offset: -3
@@ -212,9 +202,7 @@ int(8)
> Offset: -6
int(4)
> Offset: -20
Warning: strripos(): Offset not contained in string in %s on line %d
bool(false)
Offset not contained in string
------- mb_strripos -----------