Skip to content

Commit cc8c9ef

Browse files
committed
Improve the implementation of unset() on array dimensions to be more
consistent with that of regular variables and string offsets
1 parent 6096b09 commit cc8c9ef

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

Zend/zend_execute.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,10 @@ static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, znode *op
754754
fetch_string_dim:
755755
if (zend_symtable_find(ht, offset_key, offset_key_length+1, (void **) &retval) == FAILURE) {
756756
switch (type) {
757-
case BP_VAR_R:
758-
zend_error(E_NOTICE,"Undefined index: %s", offset_key);
757+
case BP_VAR_R:
758+
zend_error(E_NOTICE, "Undefined index: %s", offset_key);
759759
/* break missing intentionally */
760+
case BP_VAR_UNSET:
760761
case BP_VAR_IS:
761762
retval = &EG(uninitialized_zval_ptr);
762763
break;
@@ -786,9 +787,10 @@ static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, znode *op
786787
}
787788
if (zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) {
788789
switch (type) {
789-
case BP_VAR_R:
790+
case BP_VAR_R:
790791
zend_error(E_NOTICE,"Undefined offset: %ld", index);
791792
/* break missing intentionally */
793+
case BP_VAR_UNSET:
792794
case BP_VAR_IS:
793795
retval = &EG(uninitialized_zval_ptr);
794796
break;
@@ -808,10 +810,15 @@ static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, znode *op
808810
break;
809811
default:
810812
zend_error(E_WARNING, "Illegal offset type");
811-
if (type == BP_VAR_R || type == BP_VAR_IS) {
812-
retval = &EG(uninitialized_zval_ptr);
813-
} else {
814-
retval = &EG(error_zval_ptr);
813+
switch (type) {
814+
case BP_VAR_R:
815+
case BP_VAR_IS:
816+
case BP_VAR_UNSET:
817+
retval = &EG(uninitialized_zval_ptr);
818+
break;
819+
default:
820+
retval = &EG(error_zval_ptr);
821+
break;
815822
}
816823
break;
817824
}
@@ -898,8 +905,15 @@ static void zend_fetch_dimension_address(znode *result, znode *op1, znode *op2,
898905
convert_to_long(&tmp);
899906
offset = &tmp;
900907
}
901-
if (type!=BP_VAR_R && type!=BP_VAR_IS) {
902-
SEPARATE_ZVAL_IF_NOT_REF(container_ptr);
908+
switch (type) {
909+
case BP_VAR_R:
910+
case BP_VAR_IS:
911+
case BP_VAR_UNSET:
912+
/* do nothing... */
913+
break;
914+
default:
915+
SEPARATE_ZVAL_IF_NOT_REF(container_ptr);
916+
break;
903917
}
904918
container = *container_ptr;
905919
T(result->u.var).str_offset.str = container;
@@ -933,10 +947,18 @@ static void zend_fetch_dimension_address(znode *result, znode *op1, znode *op2,
933947
break;
934948
default: {
935949
get_zval_ptr(op2, Ts, &EG(free_op2), BP_VAR_R);
936-
if (type==BP_VAR_R || type==BP_VAR_IS) {
937-
*retval = &EG(uninitialized_zval_ptr);
938-
} else {
939-
*retval = &EG(error_zval_ptr);
950+
951+
switch (type) {
952+
case BP_VAR_UNSET:
953+
zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
954+
/* break missing intentionally */
955+
case BP_VAR_R:
956+
case BP_VAR_IS:
957+
*retval = &EG(uninitialized_zval_ptr);
958+
break;
959+
default:
960+
*retval = &EG(error_zval_ptr);
961+
break;
940962
}
941963
FREE_OP(Ts, op2, EG(free_op2));
942964
SELECTIVE_PZVAL_LOCK(**retval, result);
@@ -1970,7 +1992,7 @@ int zend_fetch_dim_unset_handler(ZEND_OPCODE_HANDLER_ARGS)
19701992
PZVAL_LOCK(*EX_T(opline->op1.u.var).var.ptr_ptr);
19711993
}
19721994
*/
1973-
zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
1995+
zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, EX(Ts), BP_VAR_UNSET TSRMLS_CC);
19741996
if (EX_T(opline->result.u.var).var.ptr_ptr == NULL) {
19751997
zend_error(E_ERROR, "Cannot unset string offsets");
19761998
} else {

0 commit comments

Comments
 (0)