summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-01-08 00:11:37 +0100
committerGeorge Peter Banyard <girgias@php.net>2020-01-24 23:59:22 +0100
commit986da2a436d878eb7141ef98360a216135ad80b2 (patch)
tree61937f99830a54f38c6798a1858d58e5e1baec16
parentebd00c5b652bb08683c1026552c82ddc8c2016bd (diff)
downloadphp-git-986da2a436d878eb7141ef98360a216135ad80b2.tar.gz
Convert warnings to ValueError in mb_strpos function family.
Closes GH-5109
-rw-r--r--ext/mbstring/mbstring.c6
-rw-r--r--ext/mbstring/tests/bug43840.phpt38
-rw-r--r--ext/mbstring/tests/bug43841.phpt41
-rw-r--r--ext/mbstring/tests/bug45923.phpt46
-rw-r--r--ext/mbstring/tests/mb_stripos.phpt55
-rw-r--r--ext/mbstring/tests/mb_stripos_empty_needle.phpt42
-rw-r--r--ext/mbstring/tests/mb_stripos_invalid_offset.phpt93
-rw-r--r--ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt56
-rw-r--r--ext/mbstring/tests/mb_strpos.phpt87
-rw-r--r--ext/mbstring/tests/mb_strpos_empty_needle.phpt43
-rw-r--r--ext/mbstring/tests/mb_strpos_invalid_offset.phpt93
-rw-r--r--ext/mbstring/tests/mb_strpos_offset_errors.phpt81
-rw-r--r--ext/mbstring/tests/mb_strpos_variation5.phpt58
-rw-r--r--ext/mbstring/tests/mb_strripos_empty_needle.phpt42
-rw-r--r--ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt49
-rw-r--r--ext/mbstring/tests/mb_strrpos_empty_needle.phpt42
16 files changed, 454 insertions, 418 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 053e91e5bc..1970febc54 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -2084,13 +2084,13 @@ static void handle_strpos_error(size_t error) {
case MBFL_ERROR_NOT_FOUND:
break;
case MBFL_ERROR_ENCODING:
- php_error_docref(NULL, E_WARNING, "Unknown encoding or conversion error");
+ php_error_docref(NULL, E_WARNING, "Conversion error");
break;
case MBFL_ERROR_OFFSET:
- php_error_docref(NULL, E_WARNING, "Offset not contained in string");
+ zend_value_error("Offset not contained in string");
break;
default:
- php_error_docref(NULL, E_WARNING, "Unknown error in mb_strpos");
+ zend_value_error("Unknown error in mb_strpos");
break;
}
}
diff --git a/ext/mbstring/tests/bug43840.phpt b/ext/mbstring/tests/bug43840.phpt
index 9cf7cacdb9..457356823e 100644
--- a/ext/mbstring/tests/bug43840.phpt
+++ b/ext/mbstring/tests/bug43840.phpt
@@ -26,12 +26,20 @@ $needle = base64_decode('44CC');
foreach($offsets as $i) {
echo "\n-- Offset is $i --\n";
echo "--Multibyte String:--\n";
- var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
+ try {
+ var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
echo"--ASCII String:--\n";
- var_dump(mb_strpos('This is na English ta', 'a', $i));
+ try {
+ var_dump(mb_strpos('This is na English ta', 'a', $i));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
}
?>
---EXPECTF--
+--EXPECT--
-- Offset is 20 --
--Multibyte String:--
int(20)
@@ -46,30 +54,18 @@ bool(false)
-- Offset is 22 --
--Multibyte String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--ASCII String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Offset is 53 --
--Multibyte String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--ASCII String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Offset is 54 --
--Multibyte String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--ASCII String:--
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
diff --git a/ext/mbstring/tests/bug43841.phpt b/ext/mbstring/tests/bug43841.phpt
index b353efaf77..cb24ece04a 100644
--- a/ext/mbstring/tests/bug43841.phpt
+++ b/ext/mbstring/tests/bug43841.phpt
@@ -17,50 +17,49 @@ function_exists('mb_strrpos') or die("skip mb_strrpos() is not available in this
*/
$offsets = array(-25, -24, -13, -12);
-$string_mb =
-base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvv
-JfvvJjvvJnjgII=');
-$needle = base64_decode('44CC');
+// Japanese string in UTF-8
+$string_mb = "日本語テキストです。0123456789。";
+$needle = "。";
foreach ($offsets as $i) {
echo "\n-- Offset is $i --\n";
echo "Multibyte String:\n";
- var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') );
+ try {
+ var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') );
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
echo "ASCII String:\n";
echo "mb_strrpos:\n";
- var_dump(mb_strrpos('This is na English ta', 'a', $i));
+ try {
+ var_dump(mb_strrpos('This is na English ta', 'a', $i));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
echo "strrpos:\n";
try {
var_dump(strrpos('This is na English ta', 'a', $i));
- } catch (ValueError $exception) {
- echo $exception->getMessage() . "\n";
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
}
}
?>
---EXPECTF--
+--EXPECT--
-- Offset is -25 --
Multibyte String:
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
ASCII String:
mb_strrpos:
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
strrpos:
Offset not contained in string
-- Offset is -24 --
Multibyte String:
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
ASCII String:
mb_strrpos:
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
strrpos:
Offset not contained in string
diff --git a/ext/mbstring/tests/bug45923.phpt b/ext/mbstring/tests/bug45923.phpt
index 98428d6d30..522f4ddddd 100644
--- a/ext/mbstring/tests/bug45923.phpt
+++ b/ext/mbstring/tests/bug45923.phpt
@@ -8,13 +8,13 @@ Bug #45923 (mb_st[r]ripos() offset not handled correctly)
function section($func, $haystack, $needle)
{
echo "\n------- $func -----------\n\n";
- foreach(array(0, 3, 6, 9, 11, 12, -1, -3, -6, -20) as $offset) {
+ foreach([0, 3, 6, 9, 11, 12, -1, -3, -6, -20] as $offset) {
echo "> Offset: $offset\n";
- try {
- var_dump($func($haystack,$needle,$offset));
- } catch (ValueError $exception) {
- echo $exception->getMessage() . "\n";
- }
+ try {
+ var_dump($func($haystack, $needle, $offset));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
}
}
@@ -30,7 +30,7 @@ section('mb_strrpos' , "●○◆ ●○◆ ●○◆", "●○◆");
section('strripos' , "abc abc abc" , "abc");
section('mb_strripos', "●○◆ ●○◆ ●○◆", "●○◆");
?>
---EXPECTF--
+--EXPECT--
------- strpos -----------
> Offset: 0
@@ -67,9 +67,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
> Offset: -1
bool(false)
> Offset: -3
@@ -77,9 +75,7 @@ int(8)
> Offset: -6
int(8)
> Offset: -20
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
------- stripos -----------
@@ -117,9 +113,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
> Offset: -1
bool(false)
> Offset: -3
@@ -127,9 +121,7 @@ int(8)
> Offset: -6
int(8)
> Offset: -20
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
------- strrpos -----------
@@ -167,9 +159,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
> Offset: -1
int(8)
> Offset: -3
@@ -177,9 +167,7 @@ int(8)
> Offset: -6
int(4)
> Offset: -20
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
------- strripos -----------
@@ -217,9 +205,7 @@ bool(false)
> Offset: 11
bool(false)
> Offset: 12
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
> Offset: -1
int(8)
> Offset: -3
@@ -227,6 +213,4 @@ int(8)
> Offset: -6
int(4)
> Offset: -20
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_stripos.phpt b/ext/mbstring/tests/mb_stripos.phpt
index d80169edd3..900b222c93 100644
--- a/ext/mbstring/tests/mb_stripos.phpt
+++ b/ext/mbstring/tests/mb_stripos.phpt
@@ -41,30 +41,6 @@ print mb_stripos($euc_jp, 0, -15, 'EUC-JP') . "\n";
print mb_stripos($euc_jp, 0, -43, 'EUC-JP') . "\n";
-// Invalid offset - should return false with warning
-print ("== INVALID OFFSET ==\n");
-
-$r = mb_stripos($euc_jp, 'ܸ', 44, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 'ܸ', 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, '0', 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 3, 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 0, 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 'ܸ', -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, '0', -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 3, -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 0, -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_stripos($euc_jp, 0, -44, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-
// Out of range - should return false
print ("== OUT OF RANGE ==\n");
@@ -143,37 +119,6 @@ String len: 43
33
30
0
-== INVALID OFFSET ==
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
== OUT OF RANGE ==
OK_OUT_RANGE
OK_OUT_RANGE
diff --git a/ext/mbstring/tests/mb_stripos_empty_needle.phpt b/ext/mbstring/tests/mb_stripos_empty_needle.phpt
index 31e21f1cd5..d991e8bdb5 100644
--- a/ext/mbstring/tests/mb_stripos_empty_needle.phpt
+++ b/ext/mbstring/tests/mb_stripos_empty_needle.phpt
@@ -24,10 +24,18 @@ echo "\n-- ASCII string with in range negative offset --\n";
var_dump(mb_stripos($string_ascii, '', -2));
echo "\n-- ASCII string with out of bound positive offset --\n";
-var_dump(mb_stripos($string_ascii, '', 150));
+try {
+ var_dump(mb_stripos($string_ascii, '', 150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- ASCII string with out of bound negative offset --\n";
-var_dump(mb_stripos($string_ascii, '', -150));
+try {
+ var_dump(mb_stripos($string_ascii, '', -150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string without offset --\n";
@@ -40,13 +48,21 @@ echo "\n-- Multi-byte string with in range negative offset --\n";
var_dump(mb_stripos($string_mb, '', -2));
echo "\n-- Multi-byte string with out of bound positive offset --\n";
-var_dump(mb_stripos($string_mb, '', 150));
+try {
+ var_dump(mb_stripos($string_mb, '', 150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string with out of bound negative offset --\n";
-var_dump(mb_stripos($string_mb, '', -150));
+try {
+ var_dump(mb_stripos($string_mb, '', -150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
-- ASCII string without offset --
int(0)
@@ -57,14 +73,10 @@ int(2)
int(5)
-- ASCII string with out of bound positive offset --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- ASCII string with out of bound negative offset --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string without offset --
int(0)
@@ -76,11 +88,7 @@ int(2)
int(19)
-- Multi-byte string with out of bound positive offset --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string with out of bound negative offset --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_stripos_invalid_offset.phpt b/ext/mbstring/tests/mb_stripos_invalid_offset.phpt
new file mode 100644
index 0000000000..f4ce16d010
--- /dev/null
+++ b/ext/mbstring/tests/mb_stripos_invalid_offset.phpt
@@ -0,0 +1,93 @@
+--TEST--
+mb_stripos() with invalid offsets
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+ini_set('include_path','.');
+include_once('common.inc');
+mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
+
+// Test string
+$string = '0123この文字列は日本語です。UTF-8を使っています。0123日本語は面倒臭い。';
+
+$slen = mb_strlen($string);
+echo "String len: $slen\n";
+
+print ("== INVALID OFFSET ==\n");
+
+try {
+ var_dump( mb_stripos($string, '日本語', 44));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump( mb_stripos($string, '日本語', 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump( mb_stripos($string, '0', 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, 3, 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, 0, 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, '日本語', -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, '0', -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, 3, -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, 0, -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_stripos($string, 0, -44));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+String len: 42
+== INVALID OFFSET ==
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt b/ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt
index cc05393a55..ba2875e767 100644
--- a/ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt
+++ b/ext/mbstring/tests/mb_stripos_variation5_Bug45923.phpt
@@ -36,25 +36,28 @@ $needle_mb = base64_decode('44CC');
for ($i = -30; $i <= 60; $i += 10) {
echo "\n**-- Offset is: $i --**\n";
echo "-- ASCII String --\n";
- var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
+ try {
+ var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
echo "--Multibyte String --\n";
- var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
+ try {
+ var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
}
-echo "Done";
?>
---EXPECTF--
+--EXPECT--
*** Testing mb_stripos() : usage variations ***
**-- Offset is: -30 --**
-- ASCII String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: -20 --**
-- ASCII String --
@@ -88,41 +91,24 @@ int(20)
**-- Offset is: 30 --**
-- ASCII String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 40 --**
-- ASCII String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 50 --**
-- ASCII String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 60 --**
-- ASCII String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
-Done
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strpos.phpt b/ext/mbstring/tests/mb_strpos.phpt
index 3b46a9b08f..1b689ab95d 100644
--- a/ext/mbstring/tests/mb_strpos.phpt
+++ b/ext/mbstring/tests/mb_strpos.phpt
@@ -41,51 +41,6 @@ print mb_strpos($euc_jp, 0, -15, 'EUC-JP') . "\n";
print mb_strpos($euc_jp, 0, -43, 'EUC-JP') . "\n";
-// Invalid offset - should return false with warning
-print ("== INVALID OFFSET ==\n");
-
-$r = mb_strpos($euc_jp, 'ܸ', 44, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 'ܸ', 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, '0', 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 3, 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 0, 50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 'ܸ', -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, '0', -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 3, -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 0, -50, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-$r = mb_strpos($euc_jp, 0, -44, 'EUC-JP');
-($r === FALSE) ? print "OK_INVALID_OFFSET\n" : print "NG_INVALID_OFFSET\n";
-
-// Out of range - should return false
-print ("== OUT OF RANGE ==\n");
-
-$r = mb_strpos($euc_jp, 'ܸ', 40, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, '0', 40, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, 3, 40, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, 0, 40, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, 'ܸ', -3, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, '0', -3, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, 3, -3, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-$r = mb_strpos($euc_jp, 0, -3, 'EUC-JP');
-($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
-
-
// Non-existent
echo "== NON-EXISTENT ==\n";
@@ -126,7 +81,7 @@ $r = mb_strpos($euc_jp, "\n");
($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
?>
---EXPECTF--
+--EXPECT--
String len: 43
== POSITIVE OFFSET ==
10
@@ -143,46 +98,6 @@ String len: 43
33
30
0
-== INVALID OFFSET ==
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-OK_INVALID_OFFSET
-== OUT OF RANGE ==
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
-OK_OUT_RANGE
== NON-EXISTENT ==
OK_STR
OK_NEWLINE
diff --git a/ext/mbstring/tests/mb_strpos_empty_needle.phpt b/ext/mbstring/tests/mb_strpos_empty_needle.phpt
index 31612647d6..da3e984b3a 100644
--- a/ext/mbstring/tests/mb_strpos_empty_needle.phpt
+++ b/ext/mbstring/tests/mb_strpos_empty_needle.phpt
@@ -24,11 +24,18 @@ echo "\n-- ASCII string with in range negative offset --\n";
var_dump(mb_strpos($string_ascii, '', -2));
echo "\n-- ASCII string with out of bound positive offset --\n";
-var_dump(mb_strpos($string_ascii, '', 15));
+try {
+ var_dump(mb_strpos($string_ascii, '', 15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- ASCII string with out of bound negative offset --\n";
-var_dump(mb_strpos($string_ascii, '', -15));
-
+try {
+ var_dump(mb_strpos($string_ascii, '', -15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string without offset --\n";
var_dump(mb_strpos($string_mb, ''));
@@ -40,13 +47,21 @@ echo "\n-- Multi-byte string with in range negative offset --\n";
var_dump(mb_strpos($string_mb, '', -2));
echo "\n-- Multi-byte string with out of bound positive offset --\n";
-var_dump(mb_strpos($string_mb, '', 150));
+try {
+ var_dump(mb_strpos($string_mb, '', 150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string with out of bound negative offset --\n";
-var_dump(mb_strpos($string_mb, '', -150));
+try {
+ var_dump(mb_strpos($string_mb, '', -150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
-- ASCII string without offset --
int(0)
@@ -57,14 +72,10 @@ int(2)
int(5)
-- ASCII string with out of bound positive offset --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- ASCII string with out of bound negative offset --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string without offset --
int(0)
@@ -76,11 +87,7 @@ int(2)
int(19)
-- Multi-byte string with out of bound positive offset --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string with out of bound negative offset --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strpos_invalid_offset.phpt b/ext/mbstring/tests/mb_strpos_invalid_offset.phpt
new file mode 100644
index 0000000000..3e2ea65e9a
--- /dev/null
+++ b/ext/mbstring/tests/mb_strpos_invalid_offset.phpt
@@ -0,0 +1,93 @@
+--TEST--
+mb_strpos() with invalid offsets
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+ini_set('include_path','.');
+include_once('common.inc');
+mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
+
+// Test string
+$string = '0123この文字列は日本語です。UTF-8を使っています。0123日本語は面倒臭い。';
+
+$slen = mb_strlen($string);
+echo "String len: $slen\n";
+
+print ("== INVALID OFFSET ==\n");
+
+try {
+ var_dump( mb_strpos($string, '日本語', 44));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump( mb_strpos($string, '日本語', 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump( mb_strpos($string, '0', 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, 3, 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, 0, 50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, '日本語', -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, '0', -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, 3, -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, 0, -50));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+try {
+ var_dump(mb_strpos($string, 0, -44));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+String len: 42
+== INVALID OFFSET ==
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strpos_offset_errors.phpt b/ext/mbstring/tests/mb_strpos_offset_errors.phpt
index 76f22431d4..41d7e257d4 100644
--- a/ext/mbstring/tests/mb_strpos_offset_errors.phpt
+++ b/ext/mbstring/tests/mb_strpos_offset_errors.phpt
@@ -3,37 +3,54 @@ Offset errors for various strpos functions
--FILE--
<?php
-var_dump(mb_strpos("f", "bar", 3));
-var_dump(mb_strpos("f", "bar", -3));
-var_dump(mb_strrpos("f", "bar", 3));
-var_dump(mb_strrpos("f", "bar", -3));
-var_dump(mb_stripos("f", "bar", 3));
-var_dump(mb_stripos("f", "bar", -3));
-var_dump(mb_strripos("f", "bar", 3));
-var_dump(mb_strripos("f", "bar", -3));
+try {
+ var_dump(mb_strpos("f", "bar", 3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strpos("f", "bar", -3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strrpos("f", "bar", 3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strrpos("f", "bar", -3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_stripos("f", "bar", 3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_stripos("f", "bar", -3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strripos("f", "bar", 3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strripos("f", "bar", -3));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_stripos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+--EXPECT--
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strpos_variation5.phpt b/ext/mbstring/tests/mb_strpos_variation5.phpt
index 097c8dccb4..7c2d4cd4a5 100644
--- a/ext/mbstring/tests/mb_strpos_variation5.phpt
+++ b/ext/mbstring/tests/mb_strpos_variation5.phpt
@@ -30,31 +30,34 @@ $needle_mb = base64_decode('44CC');
/*
* Loop through integers as multiples of ten for $offset argument
- * mb_strpos should not be able to accept negative values as $offset.
* 60 is larger than *BYTE* count for $string_mb
*/
for ($i = -30; $i <= 60; $i += 10) {
echo "\n**-- Offset is: $i --**\n";
echo "-- ASCII String --\n";
- var_dump(mb_strpos($string_ascii, $needle_ascii, $i));
+ try {
+ var_dump(mb_strpos($string_ascii, $needle_ascii, $i));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
+
echo "--Multibyte String --\n";
- var_dump(mb_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
+ try {
+ var_dump(mb_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
}
-echo "Done";
?>
---EXPECTF--
+--EXPECT--
*** Testing mb_strpos() : usage variations ***
**-- Offset is: -30 --**
-- ASCII String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: -20 --**
-- ASCII String --
@@ -88,41 +91,24 @@ int(20)
**-- Offset is: 30 --**
-- ASCII String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 40 --**
-- ASCII String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 50 --**
-- ASCII String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 60 --**
-- ASCII String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strpos(): Offset not contained in string in %s on line %d
-bool(false)
-Done
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strripos_empty_needle.phpt b/ext/mbstring/tests/mb_strripos_empty_needle.phpt
index fdd873d1fb..7d41b05a61 100644
--- a/ext/mbstring/tests/mb_strripos_empty_needle.phpt
+++ b/ext/mbstring/tests/mb_strripos_empty_needle.phpt
@@ -24,10 +24,18 @@ echo "\n-- ASCII string with in range negative offset --\n";
var_dump(mb_strripos($string_ascii, '', -2));
echo "\n-- ASCII string with out of bound positive offset --\n";
-var_dump(mb_strripos($string_ascii, '', 15));
+try {
+ var_dump(mb_strripos($string_ascii, '', 15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- ASCII string with out of bound negative offset --\n";
-var_dump(mb_strripos($string_ascii, '', -15));
+try {
+ var_dump(mb_strripos($string_ascii, '', -15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string without offset --\n";
@@ -40,13 +48,21 @@ echo "\n-- Multi-byte string with in range negative offset --\n";
var_dump(mb_strripos($string_mb, '', -2));
echo "\n-- Multi-byte string with out of bound positive offset --\n";
-var_dump(mb_strripos($string_mb, '', 150));
+try {
+ var_dump(mb_strripos($string_mb, '', 150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string with out of bound negative offset --\n";
-var_dump(mb_strripos($string_mb, '', -150));
+try {
+ var_dump(mb_strripos($string_mb, '', -150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
-- ASCII string without offset --
int(7)
@@ -57,14 +73,10 @@ int(7)
int(5)
-- ASCII string with out of bound positive offset --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- ASCII string with out of bound negative offset --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string without offset --
int(21)
@@ -76,11 +88,7 @@ int(21)
int(19)
-- Multi-byte string with out of bound positive offset --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string with out of bound negative offset --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt b/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt
index 402969d6d9..90235d6064 100644
--- a/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt
+++ b/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt
@@ -37,14 +37,22 @@ $needle_mb = base64_decode('44CC');
for ($i = -10; $i <= 60; $i += 10) {
echo "\n**-- Offset is: $i --**\n";
echo "-- ASCII String --\n";
- var_dump(mb_strripos($string_ascii, $needle_ascii, $i));
+ try {
+ var_dump(mb_strripos($string_ascii, $needle_ascii, $i));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
+
echo "--Multibyte String --\n";
- var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
+ try {
+ var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
}
-echo "Done";
?>
---EXPECTF--
+--EXPECT--
*** Testing mb_strripos() : usage variations ***
**-- Offset is: -10 --**
@@ -73,41 +81,24 @@ int(20)
**-- Offset is: 30 --**
-- ASCII String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 40 --**
-- ASCII String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 50 --**
-- ASCII String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
**-- Offset is: 60 --**
-- ASCII String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
--Multibyte String --
-
-Warning: mb_strripos(): Offset not contained in string in %s on line %d
-bool(false)
-Done
+Offset not contained in string
diff --git a/ext/mbstring/tests/mb_strrpos_empty_needle.phpt b/ext/mbstring/tests/mb_strrpos_empty_needle.phpt
index 41e4bf5239..974c44dac0 100644
--- a/ext/mbstring/tests/mb_strrpos_empty_needle.phpt
+++ b/ext/mbstring/tests/mb_strrpos_empty_needle.phpt
@@ -24,10 +24,18 @@ echo "\n-- ASCII string with in range negative offset --\n";
var_dump(mb_strrpos($string_ascii, '', -2));
echo "\n-- ASCII string with out of bound positive offset --\n";
-var_dump(mb_strrpos($string_ascii, '', 15));
+try {
+ var_dump(mb_strrpos($string_ascii, '', 15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- ASCII string with out of bound negative offset --\n";
-var_dump(mb_strrpos($string_ascii, '', -15));
+try {
+ var_dump(mb_strrpos($string_ascii, '', -15));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string without offset --\n";
@@ -40,13 +48,21 @@ echo "\n-- Multi-byte string with in range negative offset --\n";
var_dump(mb_strrpos($string_mb, '', -2));
echo "\n-- Multi-byte string with out of bound positive offset --\n";
-var_dump(mb_strrpos($string_mb, '', 150));
+try {
+ var_dump(mb_strrpos($string_mb, '', 150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "\n-- Multi-byte string with out of bound negative offset --\n";
-var_dump(mb_strrpos($string_mb, '', -150));
+try {
+ var_dump(mb_strrpos($string_mb, '', -150));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
-- ASCII string without offset --
int(7)
@@ -57,14 +73,10 @@ int(7)
int(5)
-- ASCII string with out of bound positive offset --
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- ASCII string with out of bound negative offset --
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string without offset --
int(21)
@@ -76,11 +88,7 @@ int(21)
int(19)
-- Multi-byte string with out of bound positive offset --
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string
-- Multi-byte string with out of bound negative offset --
-
-Warning: mb_strrpos(): Offset not contained in string in %s on line %d
-bool(false)
+Offset not contained in string