Skip to content

Commit 84c092f

Browse files
committed
Fixed by reference parameter passing from internal functions
1 parent da75df6 commit 84c092f

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

Zend/zend_execute_API.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -837,34 +837,33 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
837837
zval *param;
838838

839839
if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
840-
if (Z_REFCOUNTED(fci->params[i])) {
841-
if (!Z_ISREF(fci->params[i]) && Z_REFCOUNT(fci->params[i]) > 1) {
842-
zval new_zval;
843-
844-
if (fci->no_separation &&
845-
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
846-
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
847-
/* hack to clean up the stack */
848-
ZVAL_LONG(&tmp, i);
849-
zend_vm_stack_push(&tmp TSRMLS_CC);
850-
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
851-
}
852-
853-
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
854-
i+1,
855-
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name->val : "",
856-
EX(function_state).function->common.scope ? "::" : "",
857-
EX(function_state).function->common.function_name->val);
858-
return FAILURE;
840+
if (!Z_REFCOUNTED(fci->params[i]) ||
841+
(!Z_ISREF(fci->params[i]) && Z_REFCOUNT(fci->params[i]) > 1)) {
842+
843+
if (fci->no_separation &&
844+
!ARG_MAY_BE_SENT_BY_REF(EX(function_state).function, i + 1)) {
845+
if (i || UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (EG(argument_stack)->top))) {
846+
/* hack to clean up the stack */
847+
ZVAL_LONG(&tmp, i);
848+
zend_vm_stack_push(&tmp TSRMLS_CC);
849+
zend_vm_stack_clear_multiple(0 TSRMLS_CC);
859850
}
860851

861-
ZVAL_DUP(&new_zval, &fci->params[i]);
862-
Z_DELREF(fci->params[i]);
863-
ZVAL_COPY_VALUE(&fci->params[i], &new_zval);
852+
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
853+
i+1,
854+
EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name->val : "",
855+
EX(function_state).function->common.scope ? "::" : "",
856+
EX(function_state).function->common.function_name->val);
857+
return FAILURE;
864858
}
859+
860+
zval_copy_ctor(&fci->params[i]);
861+
} else if (!Z_ISREF(fci->params[i])) {
862+
ZVAL_NEW_REF(&fci->params[i], &fci->params[i]);
863+
Z_ADDREF(fci->params[i]);
864+
} else if (Z_REFCOUNTED(fci->params[i])) {
865865
Z_ADDREF(fci->params[i]);
866866
}
867-
//??? Z_SET_ISREF_PP(fci->params[i]);
868867
param = &fci->params[i];
869868
} else if (Z_ISREF(fci->params[i]) &&
870869
/* don't separate references for __call */

0 commit comments

Comments
 (0)