Skip to content

Commit 6acfaa9

Browse files
committed
Merge branch 'PHP-5.6'
2 parents 419d98b + 6006a3e commit 6acfaa9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ext/spl/spl_iterators.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,7 @@ SPL_METHOD(RegexIterator, accept)
20552055
}
20562056

20572057
if (intern->u.regex.flags & REGIT_INVERTED) {
2058-
RETVAL_BOOL(Z_LVAL_P(return_value));
2058+
RETVAL_BOOL(! Z_LVAL_P(return_value));
20592059
}
20602060

20612061
if (use_copy) {
@@ -3692,6 +3692,7 @@ PHP_MINIT_FUNCTION(spl_iterators)
36923692
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
36933693
REGISTER_SPL_SUB_CLASS_EX(RegexIterator, FilterIterator, spl_dual_it_new, spl_funcs_RegexIterator);
36943694
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "USE_KEY", REGIT_USE_KEY);
3695+
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "INVERT_MATCH",REGIT_INVERTED);
36953696
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "MATCH", REGIT_MODE_MATCH);
36963697
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "GET_MATCH", REGIT_MODE_GET_MATCH);
36973698
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "ALL_MATCHES", REGIT_MODE_ALL_MATCHES);

ext/spl/tests/bug66702.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #66702 (RegexIterator inverted result works as expected)
3+
--FILE--
4+
<?php
5+
/**
6+
* @author Joshua Thijssen <[email protected]>
7+
*/
8+
9+
$it = new \ArrayIterator(array("foo", "bar", "baz"));
10+
$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH);
11+
print_r(iterator_to_array($it2));
12+
$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::INVERT_MATCH);
13+
print_r(iterator_to_array($it2));
14+
15+
$it = new \ArrayIterator(array("foo" => 1, "bar" => 2, "baz" => 3));
16+
$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY);
17+
print_r(iterator_to_array($it2));
18+
$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY | \RegexIterator::INVERT_MATCH);
19+
print_r(iterator_to_array($it2));
20+
21+
--EXPECTF--
22+
Array
23+
(
24+
[1] => bar
25+
[2] => baz
26+
)
27+
Array
28+
(
29+
[0] => foo
30+
)
31+
Array
32+
(
33+
[bar] => 2
34+
[baz] => 3
35+
)
36+
Array
37+
(
38+
[foo] => 1
39+
)
40+

0 commit comments

Comments
 (0)