]> granicus.if.org Git - php/commitdiff
Fixed bug #39775 ("Indirect modification ..." message is not shown)
authorDmitry Stogov <dmitry@php.net>
Fri, 8 Dec 2006 15:55:31 +0000 (15:55 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 8 Dec 2006 15:55:31 +0000 (15:55 +0000)
The fix breaks two SimpleXML tests those must be fixed

NEWS
Zend/tests/bug38146.phpt
Zend/tests/bug39775.phpt [new file with mode: 0755]
Zend/zend_execute.c
Zend/zend_object_handlers.c
ext/spl/tests/iterator_035.phpt
tests/classes/array_access_003.phpt
tests/classes/array_access_004.phpt
tests/classes/array_access_005.phpt
tests/classes/array_access_008.phpt
tests/classes/array_access_012.phpt

diff --git a/NEWS b/NEWS
index bcc23235d3bb17562c18ef08842559588ddd9d3c..7735cf4b820ad1a6e801ebfb9c9cf7f82b81fbe1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,7 @@ PHP                                                                        NEWS
 - Fixed FastCGI impersonation for persistent connections on Windows. (Dmitry)
 - Fixed wrong signature initialization in imagepng (Takeshi Abe)
 - Added optimization for imageline with horizontal and vertial lines (Pierre)
+- Fixed bug #39775 ("Indirect modification ..." message is not shown). (Dmitry)
 - Fixed bug #39763 (magic quotes are applied twice by ext/filter). (Tony)
 - Fixed bug #39754 (Some POSIX extension functions not thread safe).
   (Ilia, wharmby at uk dot ibm dot com)
index e321e11c8c65d5770f2a1b016fb88328f3466292..04cb1fa8a0f041aef1e044950d9c492ffe6cd496 100755 (executable)
@@ -14,6 +14,7 @@ foreach($f->bar as $key => $value) {
     print "$key => $value\n";
 }
 ?>
---EXPECT--
+--EXPECTF--
+Notice: Indirect modification of overloaded property foo::$bar has no effect in %sbug38146.php on line 10
 foo => bar
 bar => foo
diff --git a/Zend/tests/bug39775.phpt b/Zend/tests/bug39775.phpt
new file mode 100755 (executable)
index 0000000..4c6ce6b
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #39775 ("Indirect modification ..." message is not shown)
+--FILE--
+<?php
+class test {
+       var $array = array();
+       function __get($var) {
+               $v =& $this->array;
+               return $this->array;
+       }
+}
+$t = new test;
+$t->anything[] = 'bar';
+print_r($t->anything);
+?>
+--EXPECTF--
+Notice: Indirect modification of overloaded property test::$anything has no effect in %sbug39775.php on line 10
+Array
+(
+)
index c6ab1db9b97fb932e6b3c5d788f782279d0cee62..59594713ff213f4c65929e790c59ad3eaeb47ef3 100644 (file)
@@ -1162,16 +1162,21 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container
                                overloaded_result = Z_OBJ_HT_P(container)->read_dimension(container, dim, type TSRMLS_CC);
 
                                if (overloaded_result) {
-                                       switch (type) {
-                                               case BP_VAR_RW:
-                                               case BP_VAR_W:
-                                                       if (Z_TYPE_P(overloaded_result) != IS_OBJECT
-                                                               && !overloaded_result->is_ref) {
-                                                               zend_error_noreturn(E_ERROR, "Objects used as arrays in post/pre increment/decrement must return values by reference");
-                                                       }
-                                                       break;
+                                       if (type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET) {
+                                               if (overloaded_result->refcount > 0) {
+                                                       zval *tmp = overloaded_result;
+
+                                                       ALLOC_ZVAL(overloaded_result);
+                                                       *overloaded_result = *tmp;
+                                                       zval_copy_ctor(overloaded_result);
+                                                       overloaded_result->is_ref = 0;
+                                                       overloaded_result->refcount = 0;
+                                               }
+                                               if (Z_TYPE_P(overloaded_result) != IS_OBJECT) {
+                                                       zend_class_entry *ce = Z_OBJCE_P(container);
+                                                       zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name);
+                                               }
                                        }
-
                                        retval = &overloaded_result;
                                } else {
                                        retval = &EG(error_zval_ptr);
index 92e798c75486480c327914e6c5bf5d2a5f8ec994..221035b8a5278f6b4d5630fe9cd7fc7255a4853b 100644 (file)
@@ -334,14 +334,16 @@ zval *zend_std_read_property(zval *object, zval *member, int type TSRMLS_DC)
 
                        if (rv) {
                                retval = &rv;
-                               if ((type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET) && rv->refcount > 0) {
-                                       zval *tmp = rv;
-
-                                       ALLOC_ZVAL(rv);
-                                       *rv = *tmp;
-                                       zval_copy_ctor(rv);
-                                       rv->is_ref = 0;
-                                       rv->refcount = 0;
+                               if (type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET) {
+                                       if (rv->refcount > 0) {
+                                               zval *tmp = rv;
+
+                                               ALLOC_ZVAL(rv);
+                                               *rv = *tmp;
+                                               zval_copy_ctor(rv);
+                                               rv->is_ref = 0;
+                                               rv->refcount = 0;
+                                       }
                                        if (Z_TYPE_P(rv) != IS_OBJECT) {
                                                zend_error(E_NOTICE, "Indirect modification of overloaded property %s::$%s has no effect", zobj->ce->name, Z_STRVAL_P(member));
                                        }
@@ -469,19 +471,6 @@ zval *zend_std_read_dimension(zval *object, zval *offset, int type TSRMLS_DC)
                /* Undo PZVAL_LOCK() */
                retval->refcount--;
 
-               if ((type == BP_VAR_W || type == BP_VAR_RW  || type == BP_VAR_UNSET) && retval->refcount > 0) {
-                       zval *tmp = retval;
-
-                       ALLOC_ZVAL(retval);
-                       *retval = *tmp;
-                       zval_copy_ctor(retval);
-                       retval->is_ref = 0;
-                       retval->refcount = 0;
-                       if (Z_TYPE_P(retval) != IS_OBJECT) {
-                               zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name);
-                       }
-               }
-
                return retval;
        } else {
                zend_error(E_ERROR, "Cannot use object of type %s as array", ce->name);
index 9dfe35d5f4bfaa39c8a03fb1a485ee72229f6898..4fe70cb80cbfe8d2d7bca0914663f748d419c266 100644 (file)
@@ -14,4 +14,6 @@ $a[] = &$tmp;
 echo "Done\n";
 ?>
 --EXPECTF--    
+Notice: Indirect modification of overloaded element of ArrayIterator has no effect in %siterator_035.php on line 7
+
 Fatal error: Cannot assign by reference to overloaded object in %s on line %d
index 2d42665fc69b781628c40755f9fd6001432157dc..3e631125e7c25cecb906c6c4f430133bb26f34f8 100644 (file)
@@ -53,4 +53,7 @@ object::offsetGet(2)
 int(1)
 object::offsetGet(2)
 
-Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_003.php on line %d
+Notice: Indirect modification of overloaded element of object has no effect in %sarray_access_003.php on line 39
+object::offsetGet(2)
+int(1)
+===DONE===
index 17f5b7c404051c5854b98cacd4db18e957cee1b6..787496707c151d917badd8b2b6914e1a81c20ce7 100644 (file)
@@ -51,4 +51,7 @@ object::offsetGet(2)
 int(1)
 object::offsetGet(2)
 
-Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_004.php on line %d
+Notice: Indirect modification of overloaded element of object has no effect in %sarray_access_004.php on line 39
+object::offsetGet(2)
+int(1)
+===DONE===
index 3832c536f35822c9ee5f50e4b804fc3c39cee40e..dcb873ff5683feb59684aa2a7e8e3343142ae486 100755 (executable)
@@ -70,5 +70,8 @@ array(1) {
 }
 
 Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 46
+string(6) "JoeFoo"
 
-Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_005.php on line %d
+Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 48
+string(6) "JoeFoo"
+===DONE===
index 2b577c49e0dbd667543da6e4d71b4dbaa3bec042..99798891743f0cd273c0920241f81d820a6145cb 100755 (executable)
@@ -57,5 +57,11 @@ string(9) "FooBarBaz"
 string(3) "Foo"
 
 Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 40
+string(3) "Foo"
+
+Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 42
+string(3) "Foo"
 
-Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_008.php on line %d
+Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 44
+string(3) "Foo"
+===DONE===
index 937dc3589bef51bc64f1ac8cfdc7baf3ba175942..8f85f296eb9a485556b37f2c98b31938b66014e1 100755 (executable)
@@ -33,4 +33,4 @@ $data['element'] = &$test;
 
 Notice: Indirect modification of overloaded element of ArrayAccessImpl has no effect in %sarray_access_012.php on line 24
 
-Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_012.php on line %d
+Fatal error: Cannot assign by reference to overloaded object in %sarray_access_012.php on line 24