]> granicus.if.org Git - php/commitdiff
fix for delete $this and unset $this
authorStanislav Malyshev <stas@php.net>
Thu, 14 Mar 2002 16:00:48 +0000 (16:00 +0000)
committerStanislav Malyshev <stas@php.net>
Thu, 14 Mar 2002 16:00:48 +0000 (16:00 +0000)
Zend/zend_execute.c

index ce33a59b83cd281972cba4cfa7e4442870ab3631..3eba1da4f834a9502b82eb1449a6cb031b7f1c0e 100644 (file)
@@ -2813,29 +2813,44 @@ send_by_ref:
                                        zval **object;
                                        zend_bool unset_object;
 
-                                       if (variable->type != IS_STRING) {
-                                               tmp = *variable;
-                                               zval_copy_ctor(&tmp);
-                                               convert_to_string(&tmp);
-                                               variable = &tmp;
-                                       }
-
+                       
                                        unset_object = (EX(opline)->extended_value == ZEND_UNSET_OBJ);
-                                       
-                                       if (unset_object) {
-                                               if (zend_hash_find(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1, (void **)&object) == FAILURE) {
-                                                       zend_error(E_ERROR, "Cannot delete non-existing object");
+                                       if (EX(opline)->op2.u.EA.type == ZEND_FETCH_THIS) {
+                                               if (!EG(This)) {
+                                                       zend_error(E_WARNING, "Using $this in non-object context");
+                                               } else {
+                                                       object = &EG(This);
+                                                       if(unset_object) {
+                                                               Z_OBJ_HT_PP(object)->delete_obj((*object));
+                                                               zval_ptr_dtor(&EG(This));
+                                                               EG(This) = NULL;
+                                                       } else {
+                                                               zend_error(E_WARNING, "$this cannot be unset");
+                                                       }
+                                               }
+                                       } else {
+                                               if (variable->type != IS_STRING) {
+                                                       tmp = *variable;
+                                                       zval_copy_ctor(&tmp);
+                                                       convert_to_string(&tmp);
+                                                       variable = &tmp;
                                                }
-                                               if (Z_TYPE_PP(object) != IS_OBJECT) {
+
+                                               if (unset_object) {
+                                                       if (zend_hash_find(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1, (void **)&object) == FAILURE) {
+                                                               zend_error(E_ERROR, "Cannot delete non-existing object");
+                                                       }
+                                                       if (Z_TYPE_PP(object) != IS_OBJECT) {
                                                        zend_error(E_ERROR, "Cannot call delete on non-object type");
+                                                       }
+                                                       Z_OBJ_HT_PP(object)->delete_obj((*object));
                                                }
-                                               Z_OBJ_HT_PP(object)->delete_obj((*object));
-                                       }
 
-                                       zend_hash_del(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1);
+                                               zend_hash_del(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1);
 
-                                       if (variable == &tmp) {
-                                               zval_dtor(&tmp);
+                                               if (variable == &tmp) {
+                                                       zval_dtor(&tmp);
+                                               }
                                        }
                                        FREE_OP(EX(Ts), &EX(opline)->op1, EG(free_op1));
                                }