Skip to content

Commit 1f4f2ef

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: Fixed bug #68128 Conflicts: ext/spl/spl_iterators.c
2 parents d2daa19 + fb35d7c commit 1f4f2ef

8 files changed

+161
-285
lines changed

ext/spl/spl_engine.h

+30
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval *retval, z
5151
}
5252
/* }}} */
5353

54+
/* {{{ spl_instantiate_arg_n */
55+
static inline void spl_instantiate_arg_n(zend_class_entry *pce, zval *retval, int argc, zval *argv TSRMLS_DC)
56+
{
57+
zend_function *func = pce->constructor;
58+
zend_fcall_info fci;
59+
zend_fcall_info_cache fcc;
60+
zval dummy;
61+
62+
spl_instantiate(pce, retval TSRMLS_CC);
63+
64+
fci.size = sizeof(zend_fcall_info);
65+
fci.function_table = &pce->function_table;
66+
ZVAL_STR(&fci.function_name, func->common.function_name);
67+
fci.object = Z_OBJ_P(retval);
68+
fci.symbol_table = NULL;
69+
fci.retval = &dummy;
70+
fci.param_count = argc;
71+
fci.params = argv;
72+
fci.no_separation = 1;
73+
74+
fcc.initialized = 1;
75+
fcc.function_handler = func;
76+
fcc.calling_scope = EG(scope);
77+
fcc.called_scope = pce;
78+
fcc.object = Z_OBJ_P(retval);
79+
80+
zend_call_function(&fci, &fcc TSRMLS_CC);
81+
}
82+
/* }}} */
83+
5484
#endif /* SPL_ENGINE_H */
5585

5686
/*

ext/spl/spl_iterators.c

+36-7
Original file line numberDiff line numberDiff line change
@@ -2037,8 +2037,10 @@ SPL_METHOD(RegexIterator, accept)
20372037

20382038
if (Z_TYPE(intern->current.data) == IS_UNDEF) {
20392039
RETURN_FALSE;
2040+
} else if (Z_TYPE(intern->current.data) == IS_ARRAY) {
2041+
RETURN_FALSE;
20402042
}
2041-
2043+
20422044
if (intern->u.regex.flags & REGIT_USE_KEY) {
20432045
subject_ptr = &intern->current.key;
20442046
} else {
@@ -2074,8 +2076,7 @@ SPL_METHOD(RegexIterator, accept)
20742076
ZVAL_UNDEF(&intern->current.data);
20752077
php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount,
20762078
&intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
2077-
count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
2078-
RETVAL_BOOL(count > 0);
2079+
RETVAL_BOOL(Z_LVAL(zcount) > 0);
20792080
break;
20802081

20812082
case REGIT_MODE_SPLIT:
@@ -2254,7 +2255,7 @@ SPL_METHOD(RecursiveRegexIterator, __construct)
22542255
SPL_METHOD(RecursiveRegexIterator, getChildren)
22552256
{
22562257
spl_dual_it_object *intern;
2257-
zval retval, regex;
2258+
zval retval;
22582259

22592260
if (zend_parse_parameters_none() == FAILURE) {
22602261
return;
@@ -2264,13 +2265,40 @@ SPL_METHOD(RecursiveRegexIterator, getChildren)
22642265

22652266
zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
22662267
if (!EG(exception)) {
2267-
ZVAL_STR_COPY(&regex, intern->u.regex.regex);
2268-
spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), return_value, &retval, &regex TSRMLS_CC);
2269-
zval_ptr_dtor(&regex);
2268+
zval args[5];
2269+
2270+
ZVAL_COPY(&args[0], &retval);
2271+
ZVAL_STR_COPY(&args[1], intern->u.regex.regex);
2272+
ZVAL_LONG(&args[2], intern->u.regex.mode);
2273+
ZVAL_LONG(&args[3], intern->u.regex.flags);
2274+
ZVAL_LONG(&args[4], intern->u.regex.preg_flags);
2275+
2276+
spl_instantiate_arg_n(Z_OBJCE_P(getThis()), return_value, 5, args TSRMLS_CC);
2277+
2278+
zval_ptr_dtor(&args[1]);
22702279
}
22712280
zval_ptr_dtor(&retval);
22722281
} /* }}} */
22732282

2283+
SPL_METHOD(RecursiveRegexIterator, accept)
2284+
{
2285+
spl_dual_it_object *intern;
2286+
2287+
if (zend_parse_parameters_none() == FAILURE) {
2288+
return;
2289+
}
2290+
2291+
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
2292+
2293+
if (Z_TYPE(intern->current.data) == IS_UNDEF) {
2294+
RETURN_FALSE;
2295+
} else if (Z_TYPE(intern->current.data) == IS_ARRAY) {
2296+
RETURN_BOOL(zend_hash_num_elements(Z_ARRVAL(intern->current.data)) > 0);
2297+
}
2298+
2299+
zend_call_method_with_0_params(getThis(), spl_ce_RegexIterator, NULL, "accept", return_value);
2300+
}
2301+
22742302
#endif
22752303

22762304
/* {{{ spl_dual_it_dtor */
@@ -2456,6 +2484,7 @@ ZEND_END_ARG_INFO();
24562484

24572485
static const zend_function_entry spl_funcs_RecursiveRegexIterator[] = {
24582486
SPL_ME(RecursiveRegexIterator, __construct, arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC)
2487+
SPL_ME(RecursiveRegexIterator, accept, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24592488
SPL_ME(RecursiveFilterIterator, hasChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24602489
SPL_ME(RecursiveRegexIterator, getChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24612490
PHP_FE_END

ext/spl/tests/bug68128.phpt

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
Bug #68128 - RecursiveRegexIterator raises "Array to string conversion" notice
3+
--FILE--
4+
<?php
5+
6+
$array = new ArrayIterator(array('a', array('b', 'c')));
7+
$regex = new RegexIterator($array, '/Array/');
8+
9+
foreach ($regex as $match) {
10+
var_dump($match);
11+
}
12+
13+
$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
14+
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^(t)est(\d*)/',
15+
RecursiveRegexIterator::ALL_MATCHES, 0, PREG_PATTERN_ORDER);
16+
17+
foreach ($rRegexIterator as $key1 => $value1) {
18+
19+
if ($rRegexIterator->hasChildren()) {
20+
21+
// print all children
22+
echo "Children: ";
23+
foreach ($rRegexIterator->getChildren() as $key => $value) {
24+
print_r($value);
25+
}
26+
echo "\n";
27+
} else {
28+
echo "No children ";
29+
print_r($value1);
30+
echo "\n";
31+
}
32+
}
33+
34+
?>
35+
--EXPECT--
36+
No children Array
37+
(
38+
[0] => Array
39+
(
40+
[0] => test1
41+
)
42+
43+
[1] => Array
44+
(
45+
[0] => t
46+
)
47+
48+
[2] => Array
49+
(
50+
[0] => 1
51+
)
52+
53+
)
54+
55+
Children: Array
56+
(
57+
[0] => Array
58+
(
59+
[0] => test4
60+
)
61+
62+
[1] => Array
63+
(
64+
[0] => t
65+
)
66+
67+
[2] => Array
68+
(
69+
[0] => 4
70+
)
71+
72+
)
73+
Array
74+
(
75+
[0] => Array
76+
(
77+
[0] => test5
78+
)
79+
80+
[1] => Array
81+
(
82+
[0] => t
83+
)
84+
85+
[2] => Array
86+
(
87+
[0] => 5
88+
)
89+
90+
)
91+

ext/spl/tests/iterator_048.phpt

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ class MyRecursiveRegexIterator extends RecursiveRegexIterator
1313
var_dump($v);
1414
}
1515
}
16-
17-
function accept()
18-
{
19-
return $this->hasChildren() || parent::accept();
20-
}
2116
}
2217

2318
$ar = new RecursiveArrayIterator(array('Foo', array('Bar'), 'FooBar', array('Baz'), 'Biz'));

ext/spl/tests/iterator_050.phpt

-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ array(3) {
4646
[2]=>
4747
%s(1) "2"
4848
}
49-
50-
Notice: Array to string conversion in %siterator_050.php on line %d
5149
int(0)
5250
array(2) {
5351
[0]=>
@@ -69,8 +67,6 @@ array(2) {
6967
[1]=>
7068
%s(1) "1"
7169
}
72-
73-
Notice: Array to string conversion in %siterator_050.php on line %d
7470
object(ArrayIterator)#%d (1) {
7571
%s"storage"%s"ArrayIterator":private]=>
7672
array(9) {

0 commit comments

Comments
 (0)