- 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.
This commit is contained in:
Andi Gutmans 2002-07-14 19:23:18 +00:00
parent cda0987153
commit 7b68f5108a
6 changed files with 4 additions and 72 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -625,10 +625,6 @@ NEWLINE ("\r"|"\n"|"\r\n")
return T_NEW;
}
<ST_IN_SCRIPTING>"delete" {
return T_DELETE;
}
<ST_IN_SCRIPTING>"var" {
return T_VAR;
}