Browse files

Fixed bug #33257 (array_splice() inconsistent when passed function in…

…stead of variable)
  • Loading branch information...
1 parent 96d568f commit 21e071be0692157ab8c6a86c44911e0bc80d75a8 Dmitry Stogov committed Jun 22, 2005
Showing with 36 additions and 5 deletions.
  1. +2 −0 NEWS
  2. +17 −0 Zend/tests/bug33257.phpt
  3. +4 −2 Zend/zend_compile.c
  4. +1 −0 Zend/zend_compile.h
  5. +4 −1 Zend/zend_vm_def.h
  6. +8 −2 Zend/zend_vm_execute.h
View
2 NEWS
@@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2005, PHP 5.1 Beta 3?
- Fixed bug #33427 (ext/odbc: check if unixODBC header file exists). (Jani)
+- Fixed bug #33257 (array_splice() inconsistent when passed function instead
+ of variable). (Dmitry)
21 Jun 2005, PHP 5.1 Beta 2
- Improved PHP extension loading mechanism with support for module dependencies
View
17 Zend/tests/bug33257.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #33257 array_splice() inconsistent when passed function instead of variable
+--FILE--
+<?php
+class X {
+ protected static $arr = array("a", "b", "c");
+ public static function getArr() {
+ return self::$arr;
+ }
+}
+
+//$arr1 = X::getArr();
+array_splice(X::getArr(), 1, 1);
+print_r(X::getArr());
+?>
+--EXPECTF--
+Fatal error: Only variables can be passed by reference in %sbug33257.php on line 10
View
6 Zend/zend_compile.c
@@ -1476,6 +1476,7 @@ void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC)
int original_op=op;
zend_function **function_ptr_ptr, *function_ptr;
int send_by_reference;
+ int send_function = 0;
zend_stack_top(&CG(function_call_stack), (void **) &function_ptr_ptr);
function_ptr = *function_ptr_ptr;
@@ -1500,6 +1501,7 @@ void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC)
if (op == ZEND_SEND_VAR && zend_is_function_or_method_call(param)) {
/* Method call */
op = ZEND_SEND_VAR_NO_REF;
+ send_function = ZEND_ARG_SEND_FUNCTION;
} else if (op == ZEND_SEND_VAL && (param->op_type & (IS_VAR|IS_CV))) {
op = ZEND_SEND_VAR_NO_REF;
}
@@ -1539,9 +1541,9 @@ void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC)
if (op == ZEND_SEND_VAR_NO_REF) {
if (function_ptr) {
- opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND | send_by_reference;
+ opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND | send_by_reference | send_function;
} else {
- opline->extended_value = 0;
+ opline->extended_value = send_function;
}
} else {
if (function_ptr) {
View
1 Zend/zend_compile.h
@@ -644,6 +644,7 @@ int zendlex(znode *zendlval TSRMLS_DC);
#define ZEND_ARG_SEND_BY_REF (1<<0)
#define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
+#define ZEND_ARG_SEND_FUNCTION (1<<2)
/* Lost In Stupid Parentheses */
#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
View
5 Zend/zend_vm_def.h
@@ -2158,7 +2158,10 @@ ZEND_VM_HANDLER(106, ZEND_SEND_VAR_NO_REF, VAR|CV, ANY)
} else if (!ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
ZEND_VM_DISPATCH_TO_HELPER(zend_send_by_var_helper);
}
- {
+ if ((opline->extended_value & ZEND_ARG_SEND_FUNCTION) &&
+ !EX_T(opline->op1.u.var).var.fcall_returned_reference) {
+ zend_error(E_ERROR, "Only variables can be passed by reference");
+ } else {
zval *varptr;
zend_free_op free_op1;
varptr = GET_OP1_ZVAL_PTR(BP_VAR_R);
View
10 Zend/zend_vm_execute.h
@@ -7064,7 +7064,10 @@ static int ZEND_SEND_VAR_NO_REF_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
} else if (!ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
return zend_send_by_var_helper_SPEC_VAR(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
}
- {
+ if ((opline->extended_value & ZEND_ARG_SEND_FUNCTION) &&
+ !EX_T(opline->op1.u.var).var.fcall_returned_reference) {
+ zend_error(E_ERROR, "Only variables can be passed by reference");
+ } else {
zval *varptr;
zend_free_op free_op1;
varptr = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
@@ -19080,7 +19083,10 @@ static int ZEND_SEND_VAR_NO_REF_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
} else if (!ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
return zend_send_by_var_helper_SPEC_CV(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
}
- {
+ if ((opline->extended_value & ZEND_ARG_SEND_FUNCTION) &&
+ !EX_T(opline->op1.u.var).var.fcall_returned_reference) {
+ zend_error(E_ERROR, "Only variables can be passed by reference");
+ } else {
zval *varptr;
varptr = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);

0 comments on commit 21e071b

Please sign in to comment.