diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 350b7c35657a1..93f78909fb971 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2495,10 +2495,6 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str, ZVAL_STRINGL(&tmp, last_match, &ZSTR_VAL(subject_str)[offsets[0]]-last_match); zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } - - /* One less left to do */ - if (limit_val != -1) - limit_val--; } last_match = &ZSTR_VAL(subject_str)[offsets[1]]; @@ -2520,6 +2516,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str, } } + /* One less left to do */ + if (limit_val != -1) + limit_val--; + /* Advance to the position right after the last full match */ start_offset = offsets[1]; diff --git a/ext/pcre/tests/split3.phpt b/ext/pcre/tests/split3.phpt new file mode 100644 index 0000000000000..4a705fcb470f8 --- /dev/null +++ b/ext/pcre/tests/split3.phpt @@ -0,0 +1,64 @@ +--TEST-- +preg_split() - parenthesized expressions advance the limit count +--FILE-- + + string(1) "H" + [1]=> + string(17) "AHAHA, VERY FUNNY" +} +array(3) { + [0]=> + string(1) "H" + [1]=> + string(1) "A" + [2]=> + string(16) "HAHA, VERY FUNNY" +} +array(18) { + [0]=> + string(1) "H" + [1]=> + string(1) "A" + [2]=> + string(1) "H" + [3]=> + string(1) "A" + [4]=> + string(1) "H" + [5]=> + string(1) "A" + [6]=> + string(1) "," + [7]=> + string(1) " " + [8]=> + string(1) "V" + [9]=> + string(1) "E" + [10]=> + string(1) "R" + [11]=> + string(1) "Y" + [12]=> + string(1) " " + [13]=> + string(1) "F" + [14]=> + string(1) "U" + [15]=> + string(1) "N" + [16]=> + string(1) "N" + [17]=> + string(1) "Y" +}