Merge branch 'PHP-7.1'

This commit is contained in:
Nikita Popov 2016-09-25 12:39:33 +02:00
commit ebaba26d39
5 changed files with 75 additions and 33 deletions

View File

@ -0,0 +1,17 @@
--TEST--
call_user_func() behavior when passing literal to reference parameter
--FILE--
<?php
namespace Foo;
var_dump(call_user_func('sort', []));
var_dump(\call_user_func('sort', []));
?>
--EXPECTF--
Warning: Parameter 1 to sort() expected to be a reference, value given in %s on line %d
bool(true)
Warning: Parameter 1 to sort() expected to be a reference, value given in %s on line %d
bool(true)

View File

@ -3592,12 +3592,8 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam
zend_op *opline;
zend_compile_expr(&arg_node, arg_ast);
if (arg_node.op_type & (IS_VAR|IS_CV)) {
opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL);
} else {
opline = zend_emit_op(NULL, ZEND_SEND_VAL, &arg_node, NULL);
}
opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL);
opline->op2.num = i;
opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, i);
}

View File

@ -4713,30 +4713,24 @@ ZEND_VM_C_LABEL(send_array):
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
ZEND_VM_HANDLER(120, ZEND_SEND_USER, VAR|CV, NUM)
ZEND_VM_HANDLER(120, ZEND_SEND_USER, CONST|TMP|VAR|CV, NUM)
{
USE_OPLINE
zval *arg, *param;
zend_free_op free_op1;
SAVE_OPLINE();
arg = GET_OP1_ZVAL_PTR(BP_VAR_R);
arg = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R);
param = ZEND_CALL_VAR(EX(call), opline->result.var);
if (UNEXPECTED(ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num))) {
ZVAL_DEREF(arg);
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
opline->op2.num,
EX(call)->func->common.scope ? ZSTR_VAL(EX(call)->func->common.scope->name) : "",
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name));
} else {
if (Z_ISREF_P(arg) &&
!(EX(call)->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
/* don't separate references for __call */
arg = Z_REFVAL_P(arg);
}
}
ZVAL_COPY(param, arg);
FREE_OP1();

View File

@ -3108,6 +3108,29 @@ send_val_by_ref:
ZEND_VM_NEXT_OPCODE();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_USER_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
zval *arg, *param;
SAVE_OPLINE();
arg = EX_CONSTANT(opline->op1);
param = ZEND_CALL_VAR(EX(call), opline->result.var);
if (UNEXPECTED(ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num))) {
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
opline->op2.num,
EX(call)->func->common.scope ? ZSTR_VAL(EX(call)->func->common.scope->name) : "",
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name));
}
ZVAL_COPY(param, arg);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BOOL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
@ -12567,6 +12590,30 @@ send_val_by_ref:
ZEND_VM_NEXT_OPCODE();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_USER_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
zval *arg, *param;
zend_free_op free_op1;
SAVE_OPLINE();
arg = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1);
param = ZEND_CALL_VAR(EX(call), opline->result.var);
if (UNEXPECTED(ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num))) {
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
opline->op2.num,
EX(call)->func->common.scope ? ZSTR_VAL(EX(call)->func->common.scope->name) : "",
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name));
}
ZVAL_COPY(param, arg);
zval_ptr_dtor_nogc(free_op1);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
USE_OPLINE
@ -16027,23 +16074,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_USER_SPEC_VAR_HANDLER(ZEN
zend_free_op free_op1;
SAVE_OPLINE();
arg = _get_zval_ptr_var(opline->op1.var, execute_data, &free_op1);
arg = _get_zval_ptr_var_deref(opline->op1.var, execute_data, &free_op1);
param = ZEND_CALL_VAR(EX(call), opline->result.var);
if (UNEXPECTED(ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num))) {
ZVAL_DEREF(arg);
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
opline->op2.num,
EX(call)->func->common.scope ? ZSTR_VAL(EX(call)->func->common.scope->name) : "",
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name));
} else {
if (Z_ISREF_P(arg) &&
!(EX(call)->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
/* don't separate references for __call */
arg = Z_REFVAL_P(arg);
}
}
ZVAL_COPY(param, arg);
zval_ptr_dtor_nogc(free_op1);
@ -35014,23 +35055,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_USER_SPEC_CV_HANDLER(ZEND
SAVE_OPLINE();
arg = _get_zval_ptr_cv_BP_VAR_R(execute_data, opline->op1.var);
arg = _get_zval_ptr_cv_deref_BP_VAR_R(execute_data, opline->op1.var);
param = ZEND_CALL_VAR(EX(call), opline->result.var);
if (UNEXPECTED(ARG_MUST_BE_SENT_BY_REF(EX(call)->func, opline->op2.num))) {
ZVAL_DEREF(arg);
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
opline->op2.num,
EX(call)->func->common.scope ? ZSTR_VAL(EX(call)->func->common.scope->name) : "",
EX(call)->func->common.scope ? "::" : "",
ZSTR_VAL(EX(call)->func->common.function_name));
} else {
if (Z_ISREF_P(arg) &&
!(EX(call)->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
/* don't separate references for __call */
arg = Z_REFVAL_P(arg);
}
}
ZVAL_COPY(param, arg);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
@ -60038,8 +60073,8 @@ void zend_init_opcodes_handlers(void)
ZEND_NULL_HANDLER,
ZEND_NULL_HANDLER,
ZEND_SEND_ARRAY_SPEC_HANDLER,
ZEND_NULL_HANDLER,
ZEND_NULL_HANDLER,
ZEND_SEND_USER_SPEC_CONST_HANDLER,
ZEND_SEND_USER_SPEC_TMP_HANDLER,
ZEND_SEND_USER_SPEC_VAR_HANDLER,
ZEND_NULL_HANDLER,
ZEND_SEND_USER_SPEC_CV_HANDLER,

View File

@ -332,7 +332,7 @@ static uint32_t zend_vm_opcodes_flags[187] = {
0x00001001,
0x01000703,
0x00000000,
0x00001001,
0x00001003,
0x00000007,
0x00000003,
0x07000003,