]> granicus.if.org Git - php/commitdiff
Fixed bug #33243 (ze1_compatibility_mode does not work as expected)
authorDmitry Stogov <dmitry@php.net>
Tue, 7 Jun 2005 07:03:28 +0000 (07:03 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 7 Jun 2005 07:03:28 +0000 (07:03 +0000)
Zend/tests/bug33243.phpt [new file with mode: 0755]
Zend/zend_objects.c

diff --git a/Zend/tests/bug33243.phpt b/Zend/tests/bug33243.phpt
new file mode 100755 (executable)
index 0000000..bb5d77c
--- /dev/null
@@ -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)
+  }
+}
index 30f6297c3dc690498fd22e7a608b3c408a6d266f..e4081ecf509e76d075d5161977db3cdb12818bd1 100644 (file)
@@ -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;