From: Andi Gutmans Date: Sun, 14 Jul 2002 19:23:18 +0000 (+0000) Subject: - Nuke delete(). It was a big mistake to introduce it and I finally X-Git-Tag: dev~300 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b68f5108acb970609842318edc68b10573867c6;p=php - Nuke delete(). It was a big mistake to introduce it and I finally - understand why Java didn't do so. - If you still want to control destruction of your object then either make - sure you kill all references or create a destruction method which you - call yourself. --- diff --git a/Zend/ZEND_CHANGES b/Zend/ZEND_CHANGES index 85c60a44e4..1e96a5a021 100644 --- a/Zend/ZEND_CHANGES +++ b/Zend/ZEND_CHANGES @@ -121,19 +121,6 @@ Changes in the Zend Engine 2.0 print $obj->address . "\n"; ?> - * Forced deletion of objects. - - The Zend Engine 1.0 had no means to force deletion of an object - if there are still references to it. The newly introduced delete - statement calls the object's destructor and frees it even if the - object is referenced by some other places in the engine. Other - references to the deleted object become stale and trying to - access them results in a fatal error. - - Note that if you have a user-defined function delete() in an old - script, this script will yield a parser error with the Zend - Engine 2.0, since 'delete' is now a reserved word. - * Nested classes (namespaces). The Zend Engine 1.0 provided only three scopes: the global diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 49a388e5c0..a927731a17 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2625,7 +2625,7 @@ void zend_do_indirect_references(znode *result, znode *num_references, znode *va } -void zend_do_unset(znode *variable, int type TSRMLS_DC) +void zend_do_unset(znode *variable TSRMLS_DC) { zend_op *last_op; @@ -2643,7 +2643,6 @@ void zend_do_unset(znode *variable, int type TSRMLS_DC) break; } - last_op->extended_value = type; } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 8e523c9df4..b51d576ff1 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -354,7 +354,7 @@ void zend_do_new_list_end(TSRMLS_D); void zend_do_cast(znode *result, znode *expr, int type TSRMLS_DC); void zend_do_include_or_eval(int type, znode *result, znode *op1 TSRMLS_DC); -void zend_do_unset(znode *variable, int type TSRMLS_DC); +void zend_do_unset(znode *variable TSRMLS_DC); void zend_do_isset_or_isempty(int type, znode *result, znode *variable TSRMLS_DC); void zend_do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token, int variable TSRMLS_DC); @@ -623,7 +623,6 @@ int zendlex(znode *zendlval TSRMLS_DC); /* unset types */ #define ZEND_UNSET_REG 0 -#define ZEND_UNSET_OBJ 1 /* var status for backpatching */ #define BP_VAR_R 0 diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 9559905d9f..fca3ff2a36 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2755,11 +2755,7 @@ send_by_ref: case ZEND_UNSET_VAR: { zval tmp, *variable = get_zval_ptr(&EX(opline)->op1, EX(Ts), &EG(free_op1), BP_VAR_R); - zval **object; - zend_bool unset_object; - - unset_object = (EX(opline)->extended_value == ZEND_UNSET_OBJ); if (variable->type != IS_STRING) { tmp = *variable; zval_copy_ctor(&tmp); @@ -2767,16 +2763,6 @@ send_by_ref: variable = &tmp; } - 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 TSRMLS_CC); - } - zend_hash_del(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1); if (variable == &tmp) { @@ -2788,10 +2774,6 @@ send_by_ref: case ZEND_UNSET_DIM_OBJ: { zval **container = get_zval_ptr_ptr(&EX(opline)->op1, EX(Ts), BP_VAR_R); zval *offset = get_zval_ptr(&EX(opline)->op2, EX(Ts), &EG(free_op2), BP_VAR_R); - zend_bool unset_object; - zval **object; - - unset_object = (EX(opline)->extended_value == ZEND_UNSET_OBJ); if (container) { HashTable *ht; @@ -2818,44 +2800,14 @@ send_by_ref: } else { index = offset->value.lval; } - - if (unset_object) { - if (zend_hash_index_find(ht, index, (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 TSRMLS_CC); - } zend_hash_index_del(ht, index); break; } case IS_STRING: - if (unset_object) { - if (zend_hash_find(ht, offset->value.str.val, offset->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 TSRMLS_CC); - } - zend_hash_del(ht, offset->value.str.val, offset->value.str.len+1); break; case IS_NULL: - if (unset_object) { - if (zend_hash_find(ht, "", sizeof(""), (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 TSRMLS_CC); - } - zend_hash_del(ht, "", sizeof("")); break; default: diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 9147534040..5d89928981 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -67,7 +67,7 @@ %left '*' '/' '%' %right '!' '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' %right '[' -%nonassoc T_NEW T_DELETE +%nonassoc T_NEW %token T_EXIT %token T_IF %left T_ELSEIF @@ -211,7 +211,6 @@ unticked_statement: T_CATCH '(' catch_or_import_class_entry T_VARIABLE ')' { zend_do_begin_catch(&$1, &$8, &$9, 1 TSRMLS_CC); } '{' inner_statement_list '}' { zend_do_end_catch(&$1 TSRMLS_CC); } additional_catches | T_THROW expr ';' { zend_do_throw(&$2 TSRMLS_CC); } - | T_DELETE variable ';' { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$2, ZEND_UNSET_OBJ TSRMLS_CC); } | T_IMPORT { zend_do_begin_import(TSRMLS_C); } import_rule T_FROM catch_or_import_class_entry { zend_do_end_import(&$5 TSRMLS_CC); } ';' ; @@ -252,7 +251,7 @@ unset_variables: ; unset_variable: - variable { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1, ZEND_UNSET_REG TSRMLS_CC); } + variable { zend_do_end_variable_parse(BP_VAR_UNSET, 0 TSRMLS_CC); zend_do_unset(&$1 TSRMLS_CC); } ; use_filename: diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index d8c2ac4d49..9044959862 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -625,10 +625,6 @@ NEWLINE ("\r"|"\n"|"\r\n") return T_NEW; } -"delete" { - return T_DELETE; -} - "var" { return T_VAR; }