From: Dmitry Stogov Date: Tue, 7 Jun 2005 07:03:28 +0000 (+0000) Subject: Fixed bug #33243 (ze1_compatibility_mode does not work as expected) X-Git-Tag: php-5.0.1b1~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=055e889bbd8a34512396d55577fa5a2c490b6a23;p=php Fixed bug #33243 (ze1_compatibility_mode does not work as expected) --- diff --git a/Zend/tests/bug33243.phpt b/Zend/tests/bug33243.phpt new file mode 100755 index 0000000000..bb5d77c7bf --- /dev/null +++ b/Zend/tests/bug33243.phpt @@ -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-- +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) + } +} diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index 30f6297c3d..e4081ecf50 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -111,9 +111,31 @@ ZEND_API zend_object *zend_objects_get_address(zval *zobject TSRMLS_DC) return (zend_object *)zend_object_store_get_object(zobject TSRMLS_CC); } +static void zval_add_ref_or_clone(zval **p) +{ + if (Z_TYPE_PP(p) == IS_OBJECT) { + if (Z_OBJ_HANDLER_PP(p, clone_obj) == NULL) { + zend_error(E_ERROR, "Trying to clone an uncloneable object of class %s", Z_OBJCE_PP(p)->name); + } else { + zval *orig = *p; + + ALLOC_ZVAL(*p); + **p = *orig; + INIT_PZVAL(*p); + (*p)->value.obj = Z_OBJ_HT_PP(p)->clone_obj(*p TSRMLS_CC); + } + } else { + (*p)->refcount++; + } +} + 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;