summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/spl/spl_array.c5
-rw-r--r--ext/spl/tests/bug73686.phpt45
2 files changed, 50 insertions, 0 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index bddf64ee57..d3fbb95991 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -473,6 +473,11 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
return;
}
+ if (UNEXPECTED(Z_ISREF_P(value) &&
+ Z_REFCOUNTED_P(value) == 1)) {
+ ZVAL_UNREF(value);
+ }
+
if (Z_REFCOUNTED_P(value)) {
Z_ADDREF_P(value);
}
diff --git a/ext/spl/tests/bug73686.phpt b/ext/spl/tests/bug73686.phpt
new file mode 100644
index 0000000000..ae9a59c4aa
--- /dev/null
+++ b/ext/spl/tests/bug73686.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #73686 (Adding settype()ed values to ArrayObject results in references)
+--FILE--
+<?php
+
+$ao = new ArrayObject;
+
+foreach ([1, 2, 3] as $i => $var)
+{
+ settype($var, 'string');
+ $ao[$i] = $var;
+}
+var_dump($ao);
+
+$ao = new ArrayObject;
+
+foreach ([1, 2, 3] as $i => $var)
+{
+ $ao[$i] = &$var;
+}
+var_dump($ao);
+?>
+--EXPECTF--
+object(ArrayObject)#%d (1) {
+ ["storage":"ArrayObject":private]=>
+ array(3) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+ [2]=>
+ string(1) "3"
+ }
+}
+object(ArrayObject)#%d (1) {
+ ["storage":"ArrayObject":private]=>
+ array(3) {
+ [0]=>
+ &int(3)
+ [1]=>
+ &int(3)
+ [2]=>
+ &int(3)
+ }
+}