1--TEST--
2Test oniguruma stack limit
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip mbstring not available');
6extension_loaded('iconv') or die('skip iconv not available');
7if (!function_exists('mb_ereg_replace')) die('skip mb_ereg_replace not available');
8if (version_compare(MB_ONIGURUMA_VERSION, '6.9.3') < 0) {
9    die('skip requires Oniguruma 6.9.3');
10}
11?>
12--FILE--
13<?php
14function mb_trim( $string, $chars = "", $chars_array = array() )
15{
16    for( $x=0; $x<iconv_strlen( $chars ); $x++ ) $chars_array[] = preg_quote( iconv_substr( $chars, $x, 1 ) );
17    $encoded_char_list = implode( "|", array_merge( array( "\s","\t","\n","\r", "\0", "\x0B" ), $chars_array ) );
18
19    $string = mb_ereg_replace( "^($encoded_char_list)*", "", $string );
20    $string = mb_ereg_replace( "($encoded_char_list)*$", "", $string );
21    return $string;
22}
23
24ini_set('mbstring.regex_stack_limit', 10000);
25var_dump(mb_trim(str_repeat(' ', 10000)));
26
27echo 'OK';
28?>
29--EXPECTF--
30Warning: mb_ereg_replace(): mbregex search failure in php_mbereg_replace_exec(): match-stack limit over in %s on line %d
31string(0) ""
32OK
33