Skip to content

Commit fb35d7c

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fixed bug #68128
2 parents 4773c1d + 71ba533 commit fb35d7c

9 files changed

+185
-283
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ PHP NEWS
4242
. Fixed bug #68087 (ODBC not correctly reading DATE column when preceded by
4343
a VARCHAR column) (Keyur Govande)
4444

45+
- SPL:
46+
. Fixed bug #68128 (Regression in RecursiveRegexIterator) (Tjerk)
47+
4548
02 Oct 2014, PHP 5.6.1
4649

4750
- Core:

ext/spl/spl_engine.h

+35
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,41 @@ static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval **retval,
4949
}
5050
/* }}} */
5151

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

5489
/*

ext/spl/spl_iterators.c

+52-5
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,10 @@ SPL_METHOD(RegexIterator, accept)
20452045

20462046
if (intern->current.data == NULL) {
20472047
RETURN_FALSE;
2048+
} else if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
2049+
RETURN_FALSE;
20482050
}
2049-
2051+
20502052
if (intern->u.regex.flags & REGIT_USE_KEY) {
20512053
subject_ptr = intern->current.key;
20522054
} else {
@@ -2080,8 +2082,7 @@ SPL_METHOD(RegexIterator, accept)
20802082
ALLOC_INIT_ZVAL(intern->current.data);
20812083
php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount,
20822084
intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
2083-
count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
2084-
RETVAL_BOOL(count > 0);
2085+
RETVAL_BOOL(Z_LVAL(zcount) > 0);
20852086
break;
20862087

20872088
case REGIT_MODE_SPLIT:
@@ -2259,7 +2260,7 @@ SPL_METHOD(RecursiveRegexIterator, __construct)
22592260
SPL_METHOD(RecursiveRegexIterator, getChildren)
22602261
{
22612262
spl_dual_it_object *intern;
2262-
zval *retval, *regex;
2263+
zval *retval;
22632264

22642265
if (zend_parse_parameters_none() == FAILURE) {
22652266
return;
@@ -2269,16 +2270,61 @@ SPL_METHOD(RecursiveRegexIterator, getChildren)
22692270

22702271
zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
22712272
if (!EG(exception)) {
2273+
zval **args[5], *object, *regex, *mode, *flags, *preg_flags;
2274+
2275+
MAKE_STD_ZVAL(object);
22722276
MAKE_STD_ZVAL(regex);
2277+
MAKE_STD_ZVAL(mode);
2278+
MAKE_STD_ZVAL(flags);
2279+
MAKE_STD_ZVAL(preg_flags);
2280+
2281+
MAKE_COPY_ZVAL(&retval, object);
22732282
ZVAL_STRING(regex, intern->u.regex.regex, 1);
2274-
spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, retval, regex TSRMLS_CC);
2283+
ZVAL_LONG(mode, intern->u.regex.mode);
2284+
ZVAL_LONG(flags, intern->u.regex.flags);
2285+
ZVAL_LONG(preg_flags, intern->u.regex.preg_flags);
2286+
2287+
args[0] = &object;
2288+
args[1] = &regex;
2289+
args[2] = &mode;
2290+
args[3] = &flags;
2291+
args[4] = &preg_flags;
2292+
2293+
spl_instantiate_arg_n(Z_OBJCE_P(getThis()), &return_value, 5, args TSRMLS_CC);
2294+
2295+
zval_ptr_dtor(&object);
22752296
zval_ptr_dtor(&regex);
2297+
zval_ptr_dtor(&mode);
2298+
zval_ptr_dtor(&flags);
2299+
zval_ptr_dtor(&preg_flags);
22762300
}
22772301
if (retval) {
22782302
zval_ptr_dtor(&retval);
22792303
}
22802304
} /* }}} */
22812305

2306+
SPL_METHOD(RecursiveRegexIterator, accept)
2307+
{
2308+
spl_dual_it_object *intern;
2309+
zval *rv;
2310+
2311+
if (zend_parse_parameters_none() == FAILURE) {
2312+
return;
2313+
}
2314+
2315+
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
2316+
2317+
if (intern->current.data == NULL) {
2318+
RETURN_FALSE;
2319+
} else if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
2320+
RETURN_BOOL(zend_hash_num_elements(Z_ARRVAL_P(intern->current.data)) > 0);
2321+
}
2322+
2323+
zend_call_method_with_0_params(&(getThis()), spl_ce_RegexIterator, NULL, "accept", &rv);
2324+
2325+
RETURN_ZVAL(rv, 1, 1);
2326+
}
2327+
22822328
#endif
22832329

22842330
/* {{{ spl_dual_it_dtor */
@@ -2469,6 +2515,7 @@ ZEND_END_ARG_INFO();
24692515

24702516
static const zend_function_entry spl_funcs_RecursiveRegexIterator[] = {
24712517
SPL_ME(RecursiveRegexIterator, __construct, arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC)
2518+
SPL_ME(RecursiveRegexIterator, accept, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24722519
SPL_ME(RecursiveFilterIterator, hasChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24732520
SPL_ME(RecursiveRegexIterator, getChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
24742521
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)