cvs: ZendEngine2(PHP_5_2) / zend.c zend_API.c zend_execute.c zend_execute.h zend_execute_API.c zend_globals.h zend_objects.c zend_operators.c
zend_vm_def.h zend_vm_execute.h /tests bug30332.phpt bug31828.phpt bug32080.phpt bug32852.phpt bug33243.phpt bug34712.phpt bug34767.phpt
| From: | Zeev Suraski | Date: | Mon, 05 Jun 2006 13:58:53 +0000 |
| Subject: | cvs: ZendEngine2(PHP_5_2) / zend.c zend_API.c zend_execute.c zend_execute.h zend_execute_API.c zend_globals.h zend_objects.c zend_operators.c zend_vm_def.h zend_vm_execute.h /tests bug30332.phpt bug31828.phpt bug32080.phpt bug32852.phpt bug33243.phpt bug34712.phpt bug34767.phpt |
||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4971@lists.php.net to get a copy of this message | ||
zeev Mon Jun 5 13:58:53 2006 UTC
Modified files: (Branch: PHP_5_2)
/ZendEngine2 zend.c zend_API.c zend_execute.c zend_execute.h
zend_execute_API.c zend_globals.h zend_objects.c
zend_operators.c zend_vm_def.h zend_vm_execute.h
/ZendEngine2/tests bug30332.phpt bug31828.phpt bug32080.phpt
bug32852.phpt bug33243.phpt bug34712.phpt
bug34767.phpt
Log:
Restore ZE1 compatibility mode (Zend Engine part - the modules patches
will follow later today)
http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend.c?r1=1.308.2.12.2.9&r2=1.308.2.12.2.10&diff_format=u Index: ZendEngine2/zend.c diff -u ZendEngine2/zend.c:1.308.2.12.2.9 ZendEngine2/zend.c:1.308.2.12.2.10 --- ZendEngine2/zend.c:1.308.2.12.2.9 Fri Jun 2 13:30:55 2006 +++ ZendEngine2/zend.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.c,v 1.308.2.12.2.9 2006/06/02 13:30:55 dmitry Exp $ */ +/* $Id: zend.c,v 1.308.2.12.2.10 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_extensions.h" @@ -77,6 +77,7 @@ ZEND_INI_BEGIN() ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting) + STD_ZEND_INI_BOOLEAN("zend.ze1_compatibility_mode", "0", ZEND_INI_ALL, OnUpdateBool, ze1_compatibility_mode, zend_executor_globals, executor_globals) #ifdef ZEND_MULTIBYTE STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals) #endif http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_API.c?r1=1.296.2.27.2.14&r2=1.296.2.27.2.15&diff_format=u Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.296.2.27.2.14 ZendEngine2/zend_API.c:1.296.2.27.2.15 --- ZendEngine2/zend_API.c:1.296.2.27.2.14 Sun Jun 4 10:27:28 2006 +++ ZendEngine2/zend_API.c Mon Jun 5 13:58:51 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.296.2.27.2.14 2006/06/04 10:27:28 helly Exp $ */ +/* $Id: zend_API.c,v 1.296.2.27.2.15 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -154,6 +154,25 @@ while (param_count-->0) { zval **value = (zval**)(p-arg_count); + if (EG(ze1_compatibility_mode) && Z_TYPE_PP(value) == IS_OBJECT) { + zval *value_ptr; + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(*value, &class_name, &class_name_len TSRMLS_CC); + + ALLOC_ZVAL(value_ptr); + *value_ptr = **value; + INIT_PZVAL(value_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + if(!dup) { + efree(class_name); + } + value_ptr->value.obj = Z_OBJ_HANDLER_PP(value, clone_obj)(*value TSRMLS_CC); + zval_ptr_dtor(value); + *value = value_ptr; + } *(argument_array++) = value; arg_count--; } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.c?r1=1.716.2.12.2.8&r2=1.716.2.12.2.9&diff_format=u Index: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.716.2.12.2.8 ZendEngine2/zend_execute.c:1.716.2.12.2.9 --- ZendEngine2/zend_execute.c:1.716.2.12.2.8 Thu Jun 1 11:56:44 2006 +++ ZendEngine2/zend_execute.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.716.2.12.2.8 2006/06/01 11:56:44 tony2001 Exp $ */ +/* $Id: zend_execute.c,v 1.716.2.12.2.9 2006/06/05 13:58:51 zeev Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -554,11 +554,30 @@ FREE_OP(free_value); return; } - + /* here we are sure we are dealing with an object */ /* separate our value if necessary */ - if (value_op->op_type == IS_TMP_VAR) { + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + zval *orig_value = value; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(value); + *value = *orig_value; + value->is_ref = 0; + value->refcount = 0; + dup = zend_get_object_classname(orig_value, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + value->value.obj = Z_OBJ_HANDLER_P(orig_value, clone_obj)(orig_value TSRMLS_CC); + if(!dup) { + efree(class_name); + } + } else if (value_op->op_type == IS_TMP_VAR) { zval *orig_value = value; ALLOC_ZVAL(value); @@ -701,7 +720,55 @@ goto done_setting_var; } - if (PZVAL_IS_REF(variable_ptr)) { + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else if (PZVAL_IS_REF(variable_ptr)) { + if (variable_ptr != value) { + zend_uint refcount = variable_ptr->refcount; + zval garbage; + + if (type != IS_TMP_VAR) { + value->refcount++; + } + garbage = *variable_ptr; + *variable_ptr = *value; + variable_ptr->refcount = refcount; + variable_ptr->is_ref = 1; + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + if (type != IS_TMP_VAR) { + value->refcount--; + } + zendi_zval_dtor(garbage); + } + } else { + if (variable_ptr != value) { + value->refcount++; + variable_ptr->refcount--; + if (variable_ptr->refcount == 0) { + zendi_zval_dtor(*variable_ptr); + } else { + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + } + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + zval_ptr_dtor(&value); + } + } + if (!dup) { + efree(class_name); + } + } else if (PZVAL_IS_REF(variable_ptr)) { if (variable_ptr!=value) { zend_uint refcount = variable_ptr->refcount; zval garbage; @@ -791,9 +858,34 @@ static inline void zend_receive(zval **variable_ptr_ptr, zval *value TSRMLS_DC) { - (*variable_ptr_ptr)->refcount--; - *variable_ptr_ptr = value; - value->refcount++; + zval *variable_ptr = *variable_ptr_ptr; + + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else { + variable_ptr->refcount--; + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + } + if (!dup) { + efree(class_name); + } + } else { + variable_ptr->refcount--; + *variable_ptr_ptr = value; + value->refcount++; + } } /* Utility Functions for Extensions */ http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.h?r1=1.84.2.4.2.2&r2=1.84.2.4.2.3&diff_format=u Index: ZendEngine2/zend_execute.h diff -u ZendEngine2/zend_execute.h:1.84.2.4.2.2 ZendEngine2/zend_execute.h:1.84.2.4.2.3 --- ZendEngine2/zend_execute.h:1.84.2.4.2.2 Wed May 31 13:01:57 2006 +++ ZendEngine2/zend_execute.h Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.h,v 1.84.2.4.2.2 2006/05/31 13:01:57 dmitry Exp $ */ +/* $Id: zend_execute.h,v 1.84.2.4.2.3 2006/06/05 13:58:51 zeev Exp $ */ #ifndef ZEND_EXECUTE_H #define ZEND_EXECUTE_H @@ -116,8 +116,15 @@ break; } } + + if(EG(ze1_compatibility_mode)) { + result = (zend_hash_num_elements(Z_OBJPROP_P(op))?1:0); + } else { + result = 1; + } + } else { + result = 1; } - result = 1; break; default: result = 0; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.2&r2=1.331.2.20.2.3&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.2 ZendEngine2/zend_execute_API.c:1.331.2.20.2.3 --- ZendEngine2/zend_execute_API.c:1.331.2.20.2.2 Thu May 25 07:45:19 2006 +++ ZendEngine2/zend_execute_API.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.331.2.20.2.2 2006/05/25 07:45:19 dmitry Exp $ */ +/* $Id: zend_execute_API.c,v 1.331.2.20.2.3 2006/06/05 13:58:51 zeev Exp $ */ #include <stdio.h> #include <signal.h> @@ -395,6 +395,13 @@ zval_dtor(*zval_ptr); safe_free_zval_ptr_rel(*zval_ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC); } else if ((*zval_ptr)->refcount == 1) { + if ((*zval_ptr)->type == IS_OBJECT) { + TSRMLS_FETCH(); + + if (EG(ze1_compatibility_mode)) { + return; + } + } (*zval_ptr)->is_ref = 0; } } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_globals.h?r1=1.141.2.3.2.3&r2=1.141.2.3.2.4&diff_format=u Index: ZendEngine2/zend_globals.h diff -u ZendEngine2/zend_globals.h:1.141.2.3.2.3 ZendEngine2/zend_globals.h:1.141.2.3.2.4 --- ZendEngine2/zend_globals.h:1.141.2.3.2.3 Fri May 19 06:09:14 2006 +++ ZendEngine2/zend_globals.h Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_globals.h,v 1.141.2.3.2.3 2006/05/19 06:09:14 dmitry Exp $ */ +/* $Id: zend_globals.h,v 1.141.2.3.2.4 2006/06/05 13:58:51 zeev Exp $ */ #ifndef ZEND_GLOBALS_H #define ZEND_GLOBALS_H @@ -200,6 +200,7 @@ HashTable *in_autoload; zend_function *autoload_func; zend_bool full_tables_cleanup; + zend_bool ze1_compatibility_mode; /* for extended information support */ zend_bool no_extensions; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_objects.c?r1=1.56.2.3.2.3&r2=1.56.2.3.2.4&diff_format=u Index: ZendEngine2/zend_objects.c diff -u ZendEngine2/zend_objects.c:1.56.2.3.2.3 ZendEngine2/zend_objects.c:1.56.2.3.2.4 --- ZendEngine2/zend_objects.c:1.56.2.3.2.3 Wed May 31 12:59:31 2006 +++ ZendEngine2/zend_objects.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects.c,v 1.56.2.3.2.3 2006/05/31 12:59:31 dmitry Exp $ */ +/* $Id: zend_objects.c,v 1.56.2.3.2.4 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -158,8 +158,11 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC) { - zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *)); - + if (EG(ze1_compatibility_mode)) { + zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref_or_clone, (void *) NULL /* Not used anymore */, sizeof(zval *)); + } else { + zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *)); + } if (old_object->ce->clone) { zval *new_obj; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_operators.c?r1=1.208.2.4.2.2&r2=1.208.2.4.2.3&diff_format=u Index: ZendEngine2/zend_operators.c diff -u ZendEngine2/zend_operators.c:1.208.2.4.2.2 ZendEngine2/zend_operators.c:1.208.2.4.2.3 --- ZendEngine2/zend_operators.c:1.208.2.4.2.2 Thu May 25 10:01:06 2006 +++ ZendEngine2/zend_operators.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.c,v 1.208.2.4.2.2 2006/05/25 10:01:06 tony2001 Exp $ */ +/* $Id: zend_operators.c,v 1.208.2.4.2.3 2006/06/05 13:58:51 zeev Exp $ */ #include <ctype.h> @@ -340,7 +340,14 @@ return; } - zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name); + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1:0); + } + } else { + zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name); + } zval_dtor(op); ZVAL_LONG(op, retval); return; @@ -399,7 +406,15 @@ return; } - zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name); + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1.0:0.0); + } + } else { + zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name); + } + zval_dtor(op); ZVAL_DOUBLE(op, retval); break; @@ -486,6 +501,13 @@ return; } + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1:0); + } + } + zval_dtor(op); ZVAL_BOOL(op, retval); break; @@ -1452,7 +1474,15 @@ break; case IS_OBJECT: if (Z_OBJ_HT_P(op1) == Z_OBJ_HT_P(op2)) { - result->value.lval = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2)); + if (EG(ze1_compatibility_mode)) { + zend_compare_objects(result, op1, op2 TSRMLS_CC); + /* comparison returns 0 in case of equality and + * 1 in case of ineqaulity, we need to reverse it + */ + result->value.lval = !result->value.lval; + } else { + result->value.lval = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2)); + } } else { result->value.lval = 0; } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_def.h?r1=1.59.2.29.2.4&r2=1.59.2.29.2.5&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.4 ZendEngine2/zend_vm_def.h:1.59.2.29.2.5 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.4 Sun May 21 18:00:13 2006 +++ ZendEngine2/zend_vm_def.h Mon Jun 5 13:58:52 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.4 2006/05/21 18:00:13 helly Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.5 2006/06/05 13:58:52 zeev Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -2047,7 +2047,25 @@ retval_ptr = GET_OP1_ZVAL_PTR(BP_VAR_R); - if (!IS_OP1_TMP_FREE()) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!IS_OP1_TMP_FREE()) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_execute.h?r1=1.62.2.30.2.4&r2=1.62.2.30.2.5&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.4 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.5 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.4 Sun May 21 18:00:13 2006 +++ ZendEngine2/zend_vm_execute.h Mon Jun 5 13:58:52 2006 @@ -1686,7 +1686,25 @@ retval_ptr = &opline->op1.u.constant; - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -4115,7 +4133,25 @@ retval_ptr = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - if (!1) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!1) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -7036,7 +7072,25 @@ retval_ptr = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -19156,7 +19210,25 @@ retval_ptr = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug30332.phpt?r1=1.3.4.1&r2=1.3.4.2&diff_format=u Index: ZendEngine2/tests/bug30332.phpt diff -u /dev/null ZendEngine2/tests/bug30332.phpt:1.3.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug30332.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,40 @@ +--TEST-- +Bug #30332 (zend.ze1_compatibility_mode isnt fully compatable with array_push()) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class x { }; + +$first = new x; +$second = $first; +$container = array(); +array_push($container, $first); + +$first->first = " im in the first"; + +print_r($first); +print_r($second); +print_r($container); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 4 + +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 5 + +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 7 +x Object +( + [first] => im in the first +) +x Object +( +) +Array +( + [0] => x Object + ( + ) + +) http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug31828.phpt?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: ZendEngine2/tests/bug31828.phpt diff -u /dev/null ZendEngine2/tests/bug31828.phpt:1.4.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug31828.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,25 @@ +--TEST-- +Bug #31828 (Crash with zend.ze1_compatibility_mode=On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +$o = new stdClass(); +$o->id = 77; +$o->name = "Aerospace"; +$a[] = $o; +$a = $a[0]; +print_r($a); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 2 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 5 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 6 +stdClass Object +( + [id] => 77 + [name] => Aerospace +) http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug32080.phpt?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: ZendEngine2/tests/bug32080.phpt diff -u /dev/null ZendEngine2/tests/bug32080.phpt:1.4.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug32080.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,18 @@ +--TEST-- +Bug #32080 (segfault when assigning object to itself with zend.ze1_compatibility_mode=On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class test { } +$t = new test; +$t = $t; // gives segfault +var_dump($t); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'test' because of 'zend.ze1_compatibility_mode' in %sbug32080.php on line 3 + +Strict Standards: Implicit cloning object of class 'test' because of 'zend.ze1_compatibility_mode' in %sbug32080.php on line 5 +object(test)#%d (0) { +} http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug32852.phpt?r1=1.3.4.1&r2=1.3.4.2&diff_format=u Index: ZendEngine2/tests/bug32852.phpt diff -u /dev/null ZendEngine2/tests/bug32852.phpt:1.3.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug32852.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,38 @@ +--TEST-- +Bug #32852 (Crash with singleton and __destruct when zend.ze1_compatibility_mode = On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class crashme { + private static $instance = null; + + public function __construct() { + self::$instance = $this; + } + + public function __destruct() { + echo "i'm called\n"; + } + + public static function singleton() { + if (!isset(self::$instance)) { + self::$instance = new crashme(); + } + return self::$instance; + } +} + +crashme::singleton(); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 6 +i'm called + +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 15 +i'm called + +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 17 +i'm called +i'm called http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug33243.phpt?r1=1.2.4.1&r2=1.2.4.2&diff_format=u Index: ZendEngine2/tests/bug33243.phpt diff -u /dev/null ZendEngine2/tests/bug33243.phpt:1.2.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug33243.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,25 @@ +--TEST-- +Bug #33243 (ze1_compatibility_mode does not work as expected) +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +$a->y->z = 0; +$b = $a; // should perform deep copy of $a +$b->y->z = 1; // hence this should have no effect on $a +var_dump($a); +?> +--EXPECTF-- +Strict Standards: Creating default object from empty value in %sbug33243.php on line 2 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug33243.php on line 3 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug33243.php on line 5 +object(stdClass)#%d (1) { + ["y"]=> + object(stdClass)#%d (1) { + ["z"]=> + int(0) + } +} http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug34712.phpt?r1=1.1.2.1.2.1&r2=1.1.2.1.2.2&diff_format=u Index: ZendEngine2/tests/bug34712.phpt diff -u /dev/null ZendEngine2/tests/bug34712.phpt:1.1.2.1.2.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug34712.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,28 @@ +--TEST-- +Bug #34712 zend.ze1_compatibility_mode = on segfault +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +class foo { + function foo(&$obj_ref) { + $this->bar = &$obj_ref; + } +} + + +class bar { + function bar() { + $this->foo = new foo($this); + } +} + +$test = new bar; +echo "ok\n"; +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'foo' because of 'zend.ze1_compatibility_mode' in %sbug34712.php on line 11 + +Strict Standards: Implicit cloning object of class 'bar' because of 'zend.ze1_compatibility_mode' in %sbug34712.php on line 15 +ok http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug34767.phpt?r1=1.1.2.1.2.1&r2=1.1.2.1.2.2&diff_format=u Index: ZendEngine2/tests/bug34767.phpt diff -u /dev/null ZendEngine2/tests/bug34767.phpt:1.1.2.1.2.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug34767.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,33 @@ +--TEST-- +Bug #34767 (Zend Engine 1 Compatibility not copying objects correctly) +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +$a->y = &new stdClass(); +print_r($a); +$b = $a; +$a->y->z = 1; +print_r($b); +?> +--EXPECTF-- + +Strict Standards: Assigning the return value of new by reference is deprecated in %sbug34767.php on line 2 +stdClass Object +( + [y] => stdClass Object + ( + ) + +) + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug34767.php on line 4 +stdClass Object +( + [y] => stdClass Object + ( + [z] => 1 + ) + +)
http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend.c?r1=1.308.2.12.2.9&r2=1.308.2.12.2.10&diff_format=u Index: ZendEngine2/zend.c diff -u ZendEngine2/zend.c:1.308.2.12.2.9 ZendEngine2/zend.c:1.308.2.12.2.10 --- ZendEngine2/zend.c:1.308.2.12.2.9 Fri Jun 2 13:30:55 2006 +++ ZendEngine2/zend.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.c,v 1.308.2.12.2.9 2006/06/02 13:30:55 dmitry Exp $ */ +/* $Id: zend.c,v 1.308.2.12.2.10 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_extensions.h" @@ -77,6 +77,7 @@ ZEND_INI_BEGIN() ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting) + STD_ZEND_INI_BOOLEAN("zend.ze1_compatibility_mode", "0", ZEND_INI_ALL, OnUpdateBool, ze1_compatibility_mode, zend_executor_globals, executor_globals) #ifdef ZEND_MULTIBYTE STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals) #endif http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_API.c?r1=1.296.2.27.2.14&r2=1.296.2.27.2.15&diff_format=u Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.296.2.27.2.14 ZendEngine2/zend_API.c:1.296.2.27.2.15 --- ZendEngine2/zend_API.c:1.296.2.27.2.14 Sun Jun 4 10:27:28 2006 +++ ZendEngine2/zend_API.c Mon Jun 5 13:58:51 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.296.2.27.2.14 2006/06/04 10:27:28 helly Exp $ */ +/* $Id: zend_API.c,v 1.296.2.27.2.15 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -154,6 +154,25 @@ while (param_count-->0) { zval **value = (zval**)(p-arg_count); + if (EG(ze1_compatibility_mode) && Z_TYPE_PP(value) == IS_OBJECT) { + zval *value_ptr; + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(*value, &class_name, &class_name_len TSRMLS_CC); + + ALLOC_ZVAL(value_ptr); + *value_ptr = **value; + INIT_PZVAL(value_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + if(!dup) { + efree(class_name); + } + value_ptr->value.obj = Z_OBJ_HANDLER_PP(value, clone_obj)(*value TSRMLS_CC); + zval_ptr_dtor(value); + *value = value_ptr; + } *(argument_array++) = value; arg_count--; } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.c?r1=1.716.2.12.2.8&r2=1.716.2.12.2.9&diff_format=u Index: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.716.2.12.2.8 ZendEngine2/zend_execute.c:1.716.2.12.2.9 --- ZendEngine2/zend_execute.c:1.716.2.12.2.8 Thu Jun 1 11:56:44 2006 +++ ZendEngine2/zend_execute.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.716.2.12.2.8 2006/06/01 11:56:44 tony2001 Exp $ */ +/* $Id: zend_execute.c,v 1.716.2.12.2.9 2006/06/05 13:58:51 zeev Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -554,11 +554,30 @@ FREE_OP(free_value); return; } - + /* here we are sure we are dealing with an object */ /* separate our value if necessary */ - if (value_op->op_type == IS_TMP_VAR) { + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + zval *orig_value = value; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(value); + *value = *orig_value; + value->is_ref = 0; + value->refcount = 0; + dup = zend_get_object_classname(orig_value, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + value->value.obj = Z_OBJ_HANDLER_P(orig_value, clone_obj)(orig_value TSRMLS_CC); + if(!dup) { + efree(class_name); + } + } else if (value_op->op_type == IS_TMP_VAR) { zval *orig_value = value; ALLOC_ZVAL(value); @@ -701,7 +720,55 @@ goto done_setting_var; } - if (PZVAL_IS_REF(variable_ptr)) { + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else if (PZVAL_IS_REF(variable_ptr)) { + if (variable_ptr != value) { + zend_uint refcount = variable_ptr->refcount; + zval garbage; + + if (type != IS_TMP_VAR) { + value->refcount++; + } + garbage = *variable_ptr; + *variable_ptr = *value; + variable_ptr->refcount = refcount; + variable_ptr->is_ref = 1; + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + if (type != IS_TMP_VAR) { + value->refcount--; + } + zendi_zval_dtor(garbage); + } + } else { + if (variable_ptr != value) { + value->refcount++; + variable_ptr->refcount--; + if (variable_ptr->refcount == 0) { + zendi_zval_dtor(*variable_ptr); + } else { + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + } + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + zval_ptr_dtor(&value); + } + } + if (!dup) { + efree(class_name); + } + } else if (PZVAL_IS_REF(variable_ptr)) { if (variable_ptr!=value) { zend_uint refcount = variable_ptr->refcount; zval garbage; @@ -791,9 +858,34 @@ static inline void zend_receive(zval **variable_ptr_ptr, zval *value TSRMLS_DC) { - (*variable_ptr_ptr)->refcount--; - *variable_ptr_ptr = value; - value->refcount++; + zval *variable_ptr = *variable_ptr_ptr; + + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else { + variable_ptr->refcount--; + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + } + if (!dup) { + efree(class_name); + } + } else { + variable_ptr->refcount--; + *variable_ptr_ptr = value; + value->refcount++; + } } /* Utility Functions for Extensions */ http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.h?r1=1.84.2.4.2.2&r2=1.84.2.4.2.3&diff_format=u Index: ZendEngine2/zend_execute.h diff -u ZendEngine2/zend_execute.h:1.84.2.4.2.2 ZendEngine2/zend_execute.h:1.84.2.4.2.3 --- ZendEngine2/zend_execute.h:1.84.2.4.2.2 Wed May 31 13:01:57 2006 +++ ZendEngine2/zend_execute.h Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.h,v 1.84.2.4.2.2 2006/05/31 13:01:57 dmitry Exp $ */ +/* $Id: zend_execute.h,v 1.84.2.4.2.3 2006/06/05 13:58:51 zeev Exp $ */ #ifndef ZEND_EXECUTE_H #define ZEND_EXECUTE_H @@ -116,8 +116,15 @@ break; } } + + if(EG(ze1_compatibility_mode)) { + result = (zend_hash_num_elements(Z_OBJPROP_P(op))?1:0); + } else { + result = 1; + } + } else { + result = 1; } - result = 1; break; default: result = 0; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.2&r2=1.331.2.20.2.3&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.2 ZendEngine2/zend_execute_API.c:1.331.2.20.2.3 --- ZendEngine2/zend_execute_API.c:1.331.2.20.2.2 Thu May 25 07:45:19 2006 +++ ZendEngine2/zend_execute_API.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.331.2.20.2.2 2006/05/25 07:45:19 dmitry Exp $ */ +/* $Id: zend_execute_API.c,v 1.331.2.20.2.3 2006/06/05 13:58:51 zeev Exp $ */ #include <stdio.h> #include <signal.h> @@ -395,6 +395,13 @@ zval_dtor(*zval_ptr); safe_free_zval_ptr_rel(*zval_ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC); } else if ((*zval_ptr)->refcount == 1) { + if ((*zval_ptr)->type == IS_OBJECT) { + TSRMLS_FETCH(); + + if (EG(ze1_compatibility_mode)) { + return; + } + } (*zval_ptr)->is_ref = 0; } } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_globals.h?r1=1.141.2.3.2.3&r2=1.141.2.3.2.4&diff_format=u Index: ZendEngine2/zend_globals.h diff -u ZendEngine2/zend_globals.h:1.141.2.3.2.3 ZendEngine2/zend_globals.h:1.141.2.3.2.4 --- ZendEngine2/zend_globals.h:1.141.2.3.2.3 Fri May 19 06:09:14 2006 +++ ZendEngine2/zend_globals.h Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_globals.h,v 1.141.2.3.2.3 2006/05/19 06:09:14 dmitry Exp $ */ +/* $Id: zend_globals.h,v 1.141.2.3.2.4 2006/06/05 13:58:51 zeev Exp $ */ #ifndef ZEND_GLOBALS_H #define ZEND_GLOBALS_H @@ -200,6 +200,7 @@ HashTable *in_autoload; zend_function *autoload_func; zend_bool full_tables_cleanup; + zend_bool ze1_compatibility_mode; /* for extended information support */ zend_bool no_extensions; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_objects.c?r1=1.56.2.3.2.3&r2=1.56.2.3.2.4&diff_format=u Index: ZendEngine2/zend_objects.c diff -u ZendEngine2/zend_objects.c:1.56.2.3.2.3 ZendEngine2/zend_objects.c:1.56.2.3.2.4 --- ZendEngine2/zend_objects.c:1.56.2.3.2.3 Wed May 31 12:59:31 2006 +++ ZendEngine2/zend_objects.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects.c,v 1.56.2.3.2.3 2006/05/31 12:59:31 dmitry Exp $ */ +/* $Id: zend_objects.c,v 1.56.2.3.2.4 2006/06/05 13:58:51 zeev Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -158,8 +158,11 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC) { - zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *)); - + if (EG(ze1_compatibility_mode)) { + zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref_or_clone, (void *) NULL /* Not used anymore */, sizeof(zval *)); + } else { + zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *)); + } if (old_object->ce->clone) { zval *new_obj; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_operators.c?r1=1.208.2.4.2.2&r2=1.208.2.4.2.3&diff_format=u Index: ZendEngine2/zend_operators.c diff -u ZendEngine2/zend_operators.c:1.208.2.4.2.2 ZendEngine2/zend_operators.c:1.208.2.4.2.3 --- ZendEngine2/zend_operators.c:1.208.2.4.2.2 Thu May 25 10:01:06 2006 +++ ZendEngine2/zend_operators.c Mon Jun 5 13:58:51 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.c,v 1.208.2.4.2.2 2006/05/25 10:01:06 tony2001 Exp $ */ +/* $Id: zend_operators.c,v 1.208.2.4.2.3 2006/06/05 13:58:51 zeev Exp $ */ #include <ctype.h> @@ -340,7 +340,14 @@ return; } - zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name); + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1:0); + } + } else { + zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name); + } zval_dtor(op); ZVAL_LONG(op, retval); return; @@ -399,7 +406,15 @@ return; } - zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name); + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1.0:0.0); + } + } else { + zend_error(E_NOTICE, "Object of class %s could not be converted to double", Z_OBJCE_P(op)->name); + } + zval_dtor(op); ZVAL_DOUBLE(op, retval); break; @@ -486,6 +501,13 @@ return; } + if (EG(ze1_compatibility_mode)) { + HashTable *ht = Z_OBJPROP_P(op); + if (ht) { + retval = (zend_hash_num_elements(ht)?1:0); + } + } + zval_dtor(op); ZVAL_BOOL(op, retval); break; @@ -1452,7 +1474,15 @@ break; case IS_OBJECT: if (Z_OBJ_HT_P(op1) == Z_OBJ_HT_P(op2)) { - result->value.lval = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2)); + if (EG(ze1_compatibility_mode)) { + zend_compare_objects(result, op1, op2 TSRMLS_CC); + /* comparison returns 0 in case of equality and + * 1 in case of ineqaulity, we need to reverse it + */ + result->value.lval = !result->value.lval; + } else { + result->value.lval = (Z_OBJ_HANDLE_P(op1) == Z_OBJ_HANDLE_P(op2)); + } } else { result->value.lval = 0; } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_def.h?r1=1.59.2.29.2.4&r2=1.59.2.29.2.5&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.4 ZendEngine2/zend_vm_def.h:1.59.2.29.2.5 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.4 Sun May 21 18:00:13 2006 +++ ZendEngine2/zend_vm_def.h Mon Jun 5 13:58:52 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.4 2006/05/21 18:00:13 helly Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.5 2006/06/05 13:58:52 zeev Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -2047,7 +2047,25 @@ retval_ptr = GET_OP1_ZVAL_PTR(BP_VAR_R); - if (!IS_OP1_TMP_FREE()) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!IS_OP1_TMP_FREE()) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_execute.h?r1=1.62.2.30.2.4&r2=1.62.2.30.2.5&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.4 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.5 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.4 Sun May 21 18:00:13 2006 +++ ZendEngine2/zend_vm_execute.h Mon Jun 5 13:58:52 2006 @@ -1686,7 +1686,25 @@ retval_ptr = &opline->op1.u.constant; - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -4115,7 +4133,25 @@ retval_ptr = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - if (!1) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!1) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -7036,7 +7072,25 @@ retval_ptr = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; @@ -19156,7 +19210,25 @@ retval_ptr = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); - if (!0) { /* Not a temp var */ + if (EG(ze1_compatibility_mode) && Z_TYPE_P(retval_ptr) == IS_OBJECT) { + zval *ret; + char *class_name; + zend_uint class_name_len; + int dup; + + ALLOC_ZVAL(ret); + INIT_PZVAL_COPY(ret, retval_ptr); + dup = zend_get_object_classname(retval_ptr, &class_name, &class_name_len TSRMLS_CC); + if (Z_OBJ_HT_P(retval_ptr)->clone_obj == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + ret->value.obj = Z_OBJ_HT_P(retval_ptr)->clone_obj(retval_ptr TSRMLS_CC); + *EG(return_value_ptr_ptr) = ret; + if (!dup) { + efree(class_name); + } + } else if (!0) { /* Not a temp var */ if (EG(active_op_array)->return_reference == ZEND_RETURN_REF || (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0)) { zval *ret; http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug30332.phpt?r1=1.3.4.1&r2=1.3.4.2&diff_format=u Index: ZendEngine2/tests/bug30332.phpt diff -u /dev/null ZendEngine2/tests/bug30332.phpt:1.3.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug30332.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,40 @@ +--TEST-- +Bug #30332 (zend.ze1_compatibility_mode isnt fully compatable with array_push()) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class x { }; + +$first = new x; +$second = $first; +$container = array(); +array_push($container, $first); + +$first->first = " im in the first"; + +print_r($first); +print_r($second); +print_r($container); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 4 + +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 5 + +Strict Standards: Implicit cloning object of class 'x' because of 'zend.ze1_compatibility_mode' in %sbug30332.php on line 7 +x Object +( + [first] => im in the first +) +x Object +( +) +Array +( + [0] => x Object + ( + ) + +) http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug31828.phpt?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: ZendEngine2/tests/bug31828.phpt diff -u /dev/null ZendEngine2/tests/bug31828.phpt:1.4.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug31828.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,25 @@ +--TEST-- +Bug #31828 (Crash with zend.ze1_compatibility_mode=On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +$o = new stdClass(); +$o->id = 77; +$o->name = "Aerospace"; +$a[] = $o; +$a = $a[0]; +print_r($a); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 2 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 5 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug31828.php on line 6 +stdClass Object +( + [id] => 77 + [name] => Aerospace +) http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug32080.phpt?r1=1.4.4.1&r2=1.4.4.2&diff_format=u Index: ZendEngine2/tests/bug32080.phpt diff -u /dev/null ZendEngine2/tests/bug32080.phpt:1.4.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug32080.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,18 @@ +--TEST-- +Bug #32080 (segfault when assigning object to itself with zend.ze1_compatibility_mode=On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class test { } +$t = new test; +$t = $t; // gives segfault +var_dump($t); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'test' because of 'zend.ze1_compatibility_mode' in %sbug32080.php on line 3 + +Strict Standards: Implicit cloning object of class 'test' because of 'zend.ze1_compatibility_mode' in %sbug32080.php on line 5 +object(test)#%d (0) { +} http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug32852.phpt?r1=1.3.4.1&r2=1.3.4.2&diff_format=u Index: ZendEngine2/tests/bug32852.phpt diff -u /dev/null ZendEngine2/tests/bug32852.phpt:1.3.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug32852.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,38 @@ +--TEST-- +Bug #32852 (Crash with singleton and __destruct when zend.ze1_compatibility_mode = On) +--INI-- +zend.ze1_compatibility_mode=on +error_reporting=4095 +--FILE-- +<?php +class crashme { + private static $instance = null; + + public function __construct() { + self::$instance = $this; + } + + public function __destruct() { + echo "i'm called\n"; + } + + public static function singleton() { + if (!isset(self::$instance)) { + self::$instance = new crashme(); + } + return self::$instance; + } +} + +crashme::singleton(); +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 6 +i'm called + +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 15 +i'm called + +Strict Standards: Implicit cloning object of class 'crashme' because of 'zend.ze1_compatibility_mode' in %sbug32852.php on line 17 +i'm called +i'm called http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug33243.phpt?r1=1.2.4.1&r2=1.2.4.2&diff_format=u Index: ZendEngine2/tests/bug33243.phpt diff -u /dev/null ZendEngine2/tests/bug33243.phpt:1.2.4.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug33243.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,25 @@ +--TEST-- +Bug #33243 (ze1_compatibility_mode does not work as expected) +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +$a->y->z = 0; +$b = $a; // should perform deep copy of $a +$b->y->z = 1; // hence this should have no effect on $a +var_dump($a); +?> +--EXPECTF-- +Strict Standards: Creating default object from empty value in %sbug33243.php on line 2 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug33243.php on line 3 + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug33243.php on line 5 +object(stdClass)#%d (1) { + ["y"]=> + object(stdClass)#%d (1) { + ["z"]=> + int(0) + } +} http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug34712.phpt?r1=1.1.2.1.2.1&r2=1.1.2.1.2.2&diff_format=u Index: ZendEngine2/tests/bug34712.phpt diff -u /dev/null ZendEngine2/tests/bug34712.phpt:1.1.2.1.2.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug34712.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,28 @@ +--TEST-- +Bug #34712 zend.ze1_compatibility_mode = on segfault +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +class foo { + function foo(&$obj_ref) { + $this->bar = &$obj_ref; + } +} + + +class bar { + function bar() { + $this->foo = new foo($this); + } +} + +$test = new bar; +echo "ok\n"; +?> +--EXPECTF-- +Strict Standards: Implicit cloning object of class 'foo' because of 'zend.ze1_compatibility_mode' in %sbug34712.php on line 11 + +Strict Standards: Implicit cloning object of class 'bar' because of 'zend.ze1_compatibility_mode' in %sbug34712.php on line 15 +ok http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug34767.phpt?r1=1.1.2.1.2.1&r2=1.1.2.1.2.2&diff_format=u Index: ZendEngine2/tests/bug34767.phpt diff -u /dev/null ZendEngine2/tests/bug34767.phpt:1.1.2.1.2.2 --- /dev/null Mon Jun 5 13:58:53 2006 +++ ZendEngine2/tests/bug34767.phpt Mon Jun 5 13:58:52 2006 @@ -0,0 +1,33 @@ +--TEST-- +Bug #34767 (Zend Engine 1 Compatibility not copying objects correctly) +--INI-- +zend.ze1_compatibility_mode=1 +error_reporting=4095 +--FILE-- +<?php +$a->y = &new stdClass(); +print_r($a); +$b = $a; +$a->y->z = 1; +print_r($b); +?> +--EXPECTF-- + +Strict Standards: Assigning the return value of new by reference is deprecated in %sbug34767.php on line 2 +stdClass Object +( + [y] => stdClass Object + ( + ) + +) + +Strict Standards: Implicit cloning object of class 'stdClass' because of 'zend.ze1_compatibility_mode' in %sbug34767.php on line 4 +stdClass Object +( + [y] => stdClass Object + ( + [z] => 1 + ) + +)