Skip to content

Fixed bug #68128 #865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ext/spl/spl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval *retval, z
}
/* }}} */

/* {{{ spl_instantiate_arg_n */
static inline void spl_instantiate_arg_n(zend_class_entry *pce, zval *retval, int argc, zval *argv TSRMLS_DC)
{
zend_function *func = pce->constructor;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval dummy;

spl_instantiate(pce, retval TSRMLS_CC);

fci.size = sizeof(zend_fcall_info);
fci.function_table = &pce->function_table;
ZVAL_STR(&fci.function_name, func->common.function_name);
fci.object = Z_OBJ_P(retval);
fci.symbol_table = NULL;
fci.retval = &dummy;
fci.param_count = argc;
fci.params = argv;
fci.no_separation = 1;

fcc.initialized = 1;
fcc.function_handler = func;
fcc.calling_scope = EG(scope);
fcc.called_scope = pce;
fcc.object = Z_OBJ_P(retval);

zend_call_function(&fci, &fcc TSRMLS_CC);
}
/* }}} */

#endif /* SPL_ENGINE_H */

/*
Expand Down
43 changes: 36 additions & 7 deletions ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,8 +2037,10 @@ SPL_METHOD(RegexIterator, accept)

if (Z_TYPE(intern->current.data) == IS_UNDEF) {
RETURN_FALSE;
} else if (Z_TYPE(intern->current.data) == IS_ARRAY) {
RETURN_FALSE;
}

if (intern->u.regex.flags & REGIT_USE_KEY) {
subject_ptr = &intern->current.key;
} else {
Expand Down Expand Up @@ -2074,8 +2076,7 @@ SPL_METHOD(RegexIterator, accept)
ZVAL_UNDEF(&intern->current.data);
php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount,
&intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
count = zend_hash_num_elements(Z_ARRVAL(intern->current.data));
RETVAL_BOOL(count > 0);
RETVAL_BOOL(Z_LVAL(zcount) > 0);
break;

case REGIT_MODE_SPLIT:
Expand Down Expand Up @@ -2254,7 +2255,7 @@ SPL_METHOD(RecursiveRegexIterator, __construct)
SPL_METHOD(RecursiveRegexIterator, getChildren)
{
spl_dual_it_object *intern;
zval retval, regex;
zval retval;

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

zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
if (!EG(exception)) {
ZVAL_STR_COPY(&regex, intern->u.regex.regex);
spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), return_value, &retval, &regex TSRMLS_CC);
zval_ptr_dtor(&regex);
zval args[5];

ZVAL_COPY(&args[0], &retval);
ZVAL_STR_COPY(&args[1], intern->u.regex.regex);
ZVAL_LONG(&args[2], intern->u.regex.mode);
ZVAL_LONG(&args[3], intern->u.regex.flags);
ZVAL_LONG(&args[4], intern->u.regex.preg_flags);

spl_instantiate_arg_n(Z_OBJCE_P(getThis()), return_value, 5, args TSRMLS_CC);

zval_ptr_dtor(&args[1]);
}
zval_ptr_dtor(&retval);
} /* }}} */

SPL_METHOD(RecursiveRegexIterator, accept)
{
spl_dual_it_object *intern;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());

if (Z_TYPE(intern->current.data) == IS_UNDEF) {
RETURN_FALSE;
} else if (Z_TYPE(intern->current.data) == IS_ARRAY) {
RETURN_BOOL(zend_hash_num_elements(Z_ARRVAL(intern->current.data)) > 0);
}

zend_call_method_with_0_params(getThis(), spl_ce_RegexIterator, NULL, "accept", return_value);
}

#endif

/* {{{ spl_dual_it_dtor */
Expand Down Expand Up @@ -2456,6 +2484,7 @@ ZEND_END_ARG_INFO();

static const zend_function_entry spl_funcs_RecursiveRegexIterator[] = {
SPL_ME(RecursiveRegexIterator, __construct, arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveRegexIterator, accept, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveFilterIterator, hasChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveRegexIterator, getChildren, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
PHP_FE_END
Expand Down
91 changes: 91 additions & 0 deletions ext/spl/tests/bug68128.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
--TEST--
Bug #68128 - RecursiveRegexIterator raises "Array to string conversion" notice
--FILE--
<?php

$array = new ArrayIterator(array('a', array('b', 'c')));
$regex = new RegexIterator($array, '/Array/');

foreach ($regex as $match) {
var_dump($match);
}

$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^(t)est(\d*)/',
RecursiveRegexIterator::ALL_MATCHES, 0, PREG_PATTERN_ORDER);

foreach ($rRegexIterator as $key1 => $value1) {

if ($rRegexIterator->hasChildren()) {

// print all children
echo "Children: ";
foreach ($rRegexIterator->getChildren() as $key => $value) {
print_r($value);
}
echo "\n";
} else {
echo "No children ";
print_r($value1);
echo "\n";
}
}

?>
--EXPECT--
No children Array
(
[0] => Array
(
[0] => test1
)

[1] => Array
(
[0] => t
)

[2] => Array
(
[0] => 1
)

)

Children: Array
(
[0] => Array
(
[0] => test4
)

[1] => Array
(
[0] => t
)

[2] => Array
(
[0] => 4
)

)
Array
(
[0] => Array
(
[0] => test5
)

[1] => Array
(
[0] => t
)

[2] => Array
(
[0] => 5
)

)

5 changes: 0 additions & 5 deletions ext/spl/tests/iterator_048.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class MyRecursiveRegexIterator extends RecursiveRegexIterator
var_dump($v);
}
}

function accept()
{
return $this->hasChildren() || parent::accept();
}
}

$ar = new RecursiveArrayIterator(array('Foo', array('Bar'), 'FooBar', array('Baz'), 'Biz'));
Expand Down
4 changes: 0 additions & 4 deletions ext/spl/tests/iterator_050.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ array(3) {
[2]=>
%s(1) "2"
}

Notice: Array to string conversion in %siterator_050.php on line %d
int(0)
array(2) {
[0]=>
Expand All @@ -69,8 +67,6 @@ array(2) {
[1]=>
%s(1) "1"
}

Notice: Array to string conversion in %siterator_050.php on line %d
object(ArrayIterator)#%d (1) {
%s"storage"%s"ArrayIterator":private]=>
array(9) {
Expand Down
Loading