From f37ad2e1461ebc5833096ef057ada3006e29aadc Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 8 Dec 2006 16:23:04 +0000 Subject: [PATCH] Fixed bug #39775 ("Indirect modification ..." message is not shown) --- Zend/tests/bug38146.phpt | 3 ++- Zend/tests/bug39775.phpt | 20 +++++++++++++++++++ Zend/zend_execute.c | 23 ++++++++++++--------- Zend/zend_object_handlers.c | 31 ++++++++++------------------- ext/spl/tests/iterator_035.phpt | 2 ++ tests/classes/array_access_003.phpt | 10 ++++++++-- tests/classes/array_access_004.phpt | 10 ++++++++-- tests/classes/array_access_005.phpt | 10 ++++++++-- tests/classes/array_access_008.phpt | 16 +++++++++++++-- tests/classes/array_access_012.phpt | 2 +- 10 files changed, 87 insertions(+), 40 deletions(-) create mode 100755 Zend/tests/bug39775.phpt diff --git a/Zend/tests/bug38146.phpt b/Zend/tests/bug38146.phpt index e321e11c8c..04cb1fa8a0 100755 --- a/Zend/tests/bug38146.phpt +++ b/Zend/tests/bug38146.phpt @@ -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 index 0000000000..4c6ce6baf1 --- /dev/null +++ b/Zend/tests/bug39775.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #39775 ("Indirect modification ..." message is not shown) +--FILE-- +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 +( +) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 0b3a23e8fb..f21c242d04 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1166,16 +1166,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 %v has no effect", ce->name); + } } - retval = &overloaded_result; } else { retval = &EG(error_zval_ptr); diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 53ead1521f..6b266c479f 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -342,14 +342,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 %v::$%R has no effect", zobj->ce->name, Z_TYPE_P(member), Z_UNIVAL_P(member)); } @@ -477,19 +479,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 %v has no effect", ce->name); - } - } - return retval; } else { zend_error(E_ERROR, "Cannot use object of type %v as array", ce->name); diff --git a/ext/spl/tests/iterator_035.phpt b/ext/spl/tests/iterator_035.phpt index 9dfe35d5f4..4fe70cb80c 100644 --- a/ext/spl/tests/iterator_035.phpt +++ b/ext/spl/tests/iterator_035.phpt @@ -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 diff --git a/tests/classes/array_access_003.phpt b/tests/classes/array_access_003.phpt index df0fde9f79..ae7b3bdaa1 100644 --- a/tests/classes/array_access_003.phpt +++ b/tests/classes/array_access_003.phpt @@ -53,7 +53,10 @@ 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=== --UEXPECTF-- object::offsetGet(1) unicode(6) "fooBar" @@ -61,4 +64,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=== diff --git a/tests/classes/array_access_004.phpt b/tests/classes/array_access_004.phpt index 30f179966a..6c324edc92 100644 --- a/tests/classes/array_access_004.phpt +++ b/tests/classes/array_access_004.phpt @@ -51,7 +51,10 @@ 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=== --UEXPECTF-- object::offsetGet(1) unicode(6) "fooBar" @@ -59,4 +62,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=== diff --git a/tests/classes/array_access_005.phpt b/tests/classes/array_access_005.phpt index ef72d243fd..313bf42d9d 100755 --- a/tests/classes/array_access_005.phpt +++ b/tests/classes/array_access_005.phpt @@ -70,8 +70,11 @@ 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=== --UEXPECTF-- unicode(3) "Joe" unicode(6) "JoeFoo" @@ -89,5 +92,8 @@ array(1) { } Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 46 +unicode(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 +unicode(6) "JoeFoo" +===DONE=== diff --git a/tests/classes/array_access_008.phpt b/tests/classes/array_access_008.phpt index a7f86115db..64f8d06f66 100755 --- a/tests/classes/array_access_008.phpt +++ b/tests/classes/array_access_008.phpt @@ -57,8 +57,14 @@ 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=== --UEXPECTF-- unicode(3) "Foo" unicode(6) "FooBar" @@ -67,5 +73,11 @@ unicode(9) "FooBarBaz" unicode(3) "Foo" Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 40 +unicode(3) "Foo" + +Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_008.php on line 42 +unicode(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 +unicode(3) "Foo" +===DONE=== diff --git a/tests/classes/array_access_012.phpt b/tests/classes/array_access_012.phpt index 937dc3589b..8f85f296eb 100755 --- a/tests/classes/array_access_012.phpt +++ b/tests/classes/array_access_012.phpt @@ -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 -- 2.50.1