Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug #52861 unset failes with ArrayObject and deep arrays #289

Closed
wants to merge 1 commit into from

4 participants

@mwillbanks

ArrayObject fails to unset multi-dimensional arrays. This is due to the code that fools ZE to believe we have a reference check. In this case it is missing BP_VAR_UNSET whereas BP_VAR_W and BP_VAR_RW are handled. Changing this resolves the overall issue. This does not cause a break in BC other than the obvious fixing of the bug. Thanks to @auroraeosrose for helping me locate and did it!

Example:

$arrayObject(array('foo' => array('bar' => array('baz' => 'boo'))));
unset($arrayObject['foo']['bar']['baz']);
// will not work: PHP Notice:  Indirect modification of overloaded element of ArrayObject.

The patch resolves this behavior which has been broken since 5.3.4.

@mwillbanks mwillbanks Bug #52861unset failes with ArrayObject and deep arrays
When checking to make into a reference write, readwrite are checked but not unset
d46d25f
@php-pulls
Collaborator

Comment on behalf of stas at php.net:

merged

@php-pulls php-pulls closed this
@laruence
Owner

this seems introduce issue: https://bugs.php.net/bug.php?id=66127

@mapthegod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2013
  1. @mwillbanks

    Bug #52861unset failes with ArrayObject and deep arrays

    mwillbanks authored
    When checking to make into a reference write, readwrite are checked but not unset
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 1 deletion.
  1. +1 −1  ext/spl/spl_array.c
  2. +22 −0 ext/spl/tests/bug52861.phpt
View
2  ext/spl/spl_array.c
@@ -408,7 +408,7 @@ static zval *spl_array_read_dimension_ex(int check_inherited, zval *object, zval
/* When in a write context,
* ZE has to be fooled into thinking this is in a reference set
* by separating (if necessary) and returning as an is_ref=1 zval (even if refcount == 1) */
- if ((type == BP_VAR_W || type == BP_VAR_RW) && !Z_ISREF_PP(ret)) {
+ if ((type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET) && !Z_ISREF_PP(ret)) {
if (Z_REFCOUNT_PP(ret) > 1) {
zval *newval;
View
22 ext/spl/tests/bug52861.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #52861 (unset failes with ArrayObject and deep arrays)
+--FILE--
+<?php
+$arrayObject = new ArrayObject(array('foo' => array('bar' => array('baz' => 'boo'))));
+
+unset($arrayObject['foo']['bar']['baz']);
+print_r($arrayObject->getArrayCopy());
+?>
+--EXPECT--
+Array
+(
+ [foo] => Array
+ (
+ [bar] => Array
+ (
+ )
+
+ )
+
+)
+
Something went wrong with that request. Please try again.