Skip to content

Commit 0189585

Browse files
committed
Fix tick function with arguments
Tick function arguments need to be copied to fci params.
1 parent 7ec048f commit 0189585

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

Zend/tests/declare_007.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Testing declare statement with ticks with callback arguments
3+
--FILE--
4+
<?php
5+
register_tick_function(function (stdClass $object, array $array) {
6+
echo "tick: ", get_class($object), " ", count($array), "\n";
7+
}, new \stdClass(), [1, 2, 3]);
8+
function foo() { }
9+
10+
declare(ticks=1) {
11+
12+
$statement;
13+
foo();
14+
15+
}
16+
?>
17+
--EXPECT--
18+
tick: stdClass 3
19+
tick: stdClass 3

ext/standard/basic_functions.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,7 @@ void user_shutdown_function_dtor(zval *zv) /* {{{ */
16791679
void user_tick_function_dtor(user_tick_function_entry *tick_function_entry) /* {{{ */
16801680
{
16811681
zval_ptr_dtor(&tick_function_entry->fci.function_name);
1682-
for (size_t i = 0; i < tick_function_entry->fci.param_count; i++) {
1683-
zval_ptr_dtor(&tick_function_entry->fci.params[i]);
1684-
}
1682+
zend_fcall_info_args_clear(&tick_function_entry->fci, true);
16851683
}
16861684
/* }}} */
16871685

@@ -2377,17 +2375,19 @@ PHP_FUNCTION(getprotobynumber)
23772375
PHP_FUNCTION(register_tick_function)
23782376
{
23792377
user_tick_function_entry tick_fe;
2378+
zval *params;
2379+
uint32_t param_count;
23802380

2381-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "f*", &tick_fe.fci, &tick_fe.fci_cache,
2382-
&tick_fe.fci.params, &tick_fe.fci.param_count) == FAILURE) {
2383-
RETURN_THROWS();
2384-
}
2381+
ZEND_PARSE_PARAMETERS_START(1, -1)
2382+
Z_PARAM_FUNC(tick_fe.fci, tick_fe.fci_cache)
2383+
Z_PARAM_VARIADIC('+', params, param_count);
2384+
ZEND_PARSE_PARAMETERS_END();
23852385

23862386
tick_fe.calling = false;
23872387
Z_TRY_ADDREF(tick_fe.fci.function_name);
2388-
for (size_t i = 0; i < tick_fe.fci.param_count; i++) {
2389-
Z_TRY_ADDREF(tick_fe.fci.params[i]);
2390-
}
2388+
tick_fe.fci.params = NULL;
2389+
zend_fcall_info_argp(&tick_fe.fci, param_count, params);
2390+
23912391
if (!BG(user_tick_functions)) {
23922392
BG(user_tick_functions) = (zend_llist *) emalloc(sizeof(zend_llist));
23932393
zend_llist_init(BG(user_tick_functions),

0 commit comments

Comments
 (0)