com php-src: Make necessary separation (it might be possible to fix this in a better way, but this will requre some refactoring): ext/spl/spl_array.c
ext/spl/tests/arrayObject___con struct_basic7.phpt
| From: | Dmitry Stogov | Date: | Fri, 25 Sep 2015 07:59:27 +0000 |
| Subject: | com php-src: Make necessary separation (it might be possible to fix this in a better way, but this will requre some refactoring): ext/spl/spl_array.c ext/spl/tests/arrayObject___con struct_basic7.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89174@lists.php.net to get a copy of this message | ||
Commit: f509706318bcd7198faff747f0eab326f2953524
Author: Dmitry Stogov <dmitry@zend.com> Fri, 25 Sep 2015 10:59:27 +0300
Parents: b98d09a6a90b3902f2c5b1ee1fcc85c7959a1ab4
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f509706318bcd7198faff747f0eab326f2953524
Log:
Make necessary separation (it might be possible to fix this in a better way, but this will requre
some refactoring)
Changed paths:
M ext/spl/spl_array.c
A ext/spl/tests/arrayObject___construct_basic7.phpt
Diff:
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index faae6ef..ead514d 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -1099,11 +1099,19 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval
*ar
}
} else {
zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties);
- ZVAL_COPY(&intern->array, array);
if (handler != std_object_handlers.get_properties
|| !spl_array_get_hash_table(intern, 0)) {
+ ZVAL_UNDEF(&intern->array);
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Overloaded object of type %s
is not compatible with %s", Z_OBJCE_P(array)->name, intern->std.ce->name);
}
+ //??? TODO: try to avoid array duplication
+ if (Z_OBJ_P(array)->properties && GC_REFCOUNT(Z_OBJ_P(array)->properties) > 1)
{
+ if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(array)->properties) & IS_ARRAY_IMMUTABLE))) {
+ GC_REFCOUNT(Z_OBJ_P(array)->properties)--;
+ }
+ Z_OBJ_P(array)->properties = zend_array_dup(Z_OBJ_P(array)->properties);
+ }
+ ZVAL_COPY(&intern->array, array);
}
}
diff --git a/ext/spl/tests/arrayObject___construct_basic7.phpt
b/ext/spl/tests/arrayObject___construct_basic7.phpt
new file mode 100644
index 0000000..2474b38
--- /dev/null
+++ b/ext/spl/tests/arrayObject___construct_basic7.phpt
@@ -0,0 +1,34 @@
+--TEST--
+SPL: ArrayObject::__construct: Using object with shared properties
+--FILE--
+<?php
+$y = 2;
+$x = 1;
+$a = array($y, $x);
+$o = (object)$a;
+$ao = new ArrayObject($o);
+$ao->asort();
+var_dump($a, $o, $ao);
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ int(2)
+ [1]=>
+ int(1)
+}
+object(stdClass)#1 (2) {
+ [1]=>
+ int(1)
+ [0]=>
+ int(2)
+}
+object(ArrayObject)#2 (1) {
+ ["storage":"ArrayObject":private]=>
+ object(stdClass)#1 (2) {
+ [1]=>
+ int(1)
+ [0]=>
+ int(2)
+ }
+}