Skip to content

Commit 7aca138

Browse files
committed
Fixed bug #33710 (ArrayAccess objects doen't initialize $this)
1 parent a59f50f commit 7aca138

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2005, PHP 5.1
4+
- Fixed bug #33710 (ArrayAccess objects doen't initialize $this). (Dmitry)
45
- Fixed bug #33558 (warning with nested calls to functions returning by
56
reference). (Dmitry)
67

8+
79
14 Jul 2005, PHP 5.1 Beta 3
810
- Upgraded bundled SQLite library for PDO:SQLite to 3.2.2 (Ilia)
911
- Moved extensions to PECL:

Zend/zend_compile.c

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -847,55 +847,56 @@ void zend_do_end_variable_parse(int type, int arg_offset TSRMLS_DC)
847847
zend_llist *fetch_list_ptr;
848848
zend_llist_element *le;
849849
zend_op *opline, *opline_ptr=NULL;
850-
int num_of_created_opcodes = 0;
851850

852851
zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr);
853852

854853
le = fetch_list_ptr->head;
855854

856855
/* TODO: $foo->x->y->z = 1 should fetch "x" and "y" for R or RW, not just W */
857856

858-
while (le) {
857+
if (le) {
859858
opline_ptr = (zend_op *)le->data;
860-
opline = get_next_op(CG(active_op_array) TSRMLS_CC);
861-
memcpy(opline, opline_ptr, sizeof(zend_op));
862-
switch (type) {
863-
case BP_VAR_R:
864-
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
865-
zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
866-
}
867-
opline->opcode -= 3;
868-
break;
869-
case BP_VAR_W:
870-
break;
871-
case BP_VAR_RW:
872-
opline->opcode += 3;
873-
break;
874-
case BP_VAR_IS:
875-
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
876-
zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
877-
}
878-
opline->opcode += 6; /* 3+3 */
879-
break;
880-
case BP_VAR_FUNC_ARG:
881-
opline->opcode += 9; /* 3+3+3 */
882-
opline->extended_value = arg_offset;
883-
break;
884-
case BP_VAR_UNSET:
885-
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
886-
zend_error(E_COMPILE_ERROR, "Cannot use [] for unsetting");
887-
}
888-
opline->opcode += 12; /* 3+3+3+3 */
889-
break;
859+
if (opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
860+
CG(active_op_array)->uses_this = 1;
890861
}
891-
le = le->next;
892-
num_of_created_opcodes++;
893-
}
894862

895-
if (num_of_created_opcodes == 1 && opline_is_fetch_this(opline_ptr TSRMLS_CC)) {
896-
CG(active_op_array)->uses_this = 1;
863+
while (1) {
864+
opline = get_next_op(CG(active_op_array) TSRMLS_CC);
865+
memcpy(opline, opline_ptr, sizeof(zend_op));
866+
switch (type) {
867+
case BP_VAR_R:
868+
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
869+
zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
870+
}
871+
opline->opcode -= 3;
872+
break;
873+
case BP_VAR_W:
874+
break;
875+
case BP_VAR_RW:
876+
opline->opcode += 3;
877+
break;
878+
case BP_VAR_IS:
879+
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
880+
zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
881+
}
882+
opline->opcode += 6; /* 3+3 */
883+
break;
884+
case BP_VAR_FUNC_ARG:
885+
opline->opcode += 9; /* 3+3+3 */
886+
opline->extended_value = arg_offset;
887+
break;
888+
case BP_VAR_UNSET:
889+
if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) {
890+
zend_error(E_COMPILE_ERROR, "Cannot use [] for unsetting");
891+
}
892+
opline->opcode += 12; /* 3+3+3+3 */
893+
break;
894+
}
895+
le = le->next;
896+
if (le == NULL) break;
897+
opline_ptr = (zend_op *)le->data;
898+
}
897899
}
898-
899900
zend_llist_destroy(fetch_list_ptr);
900901
zend_stack_del_top(&CG(bp_stack));
901902
}

Zend/zend_execute.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,10 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container
11371137
result->var.ptr_ptr = retval;
11381138
AI_USE_PTR(result->var);
11391139
PZVAL_LOCK(*result->var.ptr_ptr);
1140+
} else if ((*retval)->refcount == 0) {
1141+
/* Destroy unused result from offsetGet() magic method */
1142+
(*retval)->refcount = 1;
1143+
zval_ptr_dtor(retval);
11401144
}
11411145
if (dim_is_tmp_var) {
11421146
zval_ptr_dtor(&dim);

0 commit comments

Comments
 (0)