1--TEST-- 2mb_ereg_search_setpos() function 3--EXTENSIONS-- 4mbstring 5--SKIPIF-- 6<?php 7if (!function_exists("mb_regex_encoding")) die("skip mb_regex_encoding() is not defined"); 8?> 9--FILE-- 10<?php 11mb_regex_encoding('iso-8859-1'); 12$test_str = 'I�t�rn�ti�n�liz�ti�n'; // Length = 20 13 14var_dump(mb_ereg_search_setpos(50)); // OK 15try { 16 var_dump(mb_ereg_search_setpos(-1)); // Error 17} catch (\ValueError $e) { 18 echo $e->getMessage() . \PHP_EOL; 19} 20 21mb_ereg_search_init($test_str); 22 23$positions = array( 5, 20, 21, 25, 0, -5, -20, -30); 24foreach($positions as $pos) { 25 echo("\n* Position: $pos :\n"); 26 try { 27 var_dump(mb_ereg_search_setpos($pos)); 28 } catch (\ValueError $e) { 29 echo $e->getMessage() . \PHP_EOL; 30 } 31 try { 32 var_dump(mb_ereg_search_getpos()); 33 } catch (\ValueError $e) { 34 echo $e->getMessage() . \PHP_EOL; 35 } 36} 37?> 38--EXPECT-- 39bool(true) 40mb_ereg_search_setpos(): Argument #1 ($offset) is out of range 41 42* Position: 5 : 43bool(true) 44int(5) 45 46* Position: 20 : 47bool(true) 48int(20) 49 50* Position: 21 : 51mb_ereg_search_setpos(): Argument #1 ($offset) is out of range 52int(20) 53 54* Position: 25 : 55mb_ereg_search_setpos(): Argument #1 ($offset) is out of range 56int(20) 57 58* Position: 0 : 59bool(true) 60int(0) 61 62* Position: -5 : 63bool(true) 64int(15) 65 66* Position: -20 : 67bool(true) 68int(0) 69 70* Position: -30 : 71mb_ereg_search_setpos(): Argument #1 ($offset) is out of range 72int(0) 73