In case USE_KEY flag is active, RegexIterator->accept() should keep it's
old behavior which is to accept keys mapping arrays.
This broke after PHP 5.5 but was not noticed due to lack of tests for USE_KEY.
if (intern->current.data == NULL) {
RETURN_FALSE;
- } else if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
- RETURN_FALSE;
}
if (intern->u.regex.flags & REGIT_USE_KEY) {
subject_ptr = intern->current.key;
} else {
+ if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
+ RETURN_FALSE;
+ }
subject_ptr = intern->current.data;
}
--- /dev/null
+--TEST--
+Bug #68128 - RecursiveRegexIterator raises "Array to string conversion" notice
+--FILE--
+<?php
+
+$arrayIterator = new ArrayIterator(array('key 1' => 'value 1', 'key 2' => ['value 2']));
+$regexIterator = new RegexIterator($arrayIterator, '/^key/', RegexIterator::MATCH, RegexIterator::USE_KEY);
+
+foreach ($regexIterator as $key => $value) {
+ var_dump($key, $value);
+}
+
+?>
+--EXPECT--
+string(5) "key 1"
+string(7) "value 1"
+string(5) "key 2"
+array(1) {
+ [0]=>
+ string(7) "value 2"
+}
bool(true)
bool(true)
bool(true)
-bool(false)
+bool(true)
bool(true)
bool(true)
bool(true)
string(1) "4"
}
}
-bool(false)
+bool(true)
+int(5)
+array(2) {
+ [0]=>
+ array(1) {
+ [0]=>
+ string(1) "5"
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ string(1) "5"
+ }
+}
bool(true)
int(6)
array(2) {