}
} 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);
}
}
--- /dev/null
+--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)
+ }
+}