@@ -807,18 +807,40 @@ SPL_METHOD(Array, getArrayCopy)
807
807
RETURN_ARR (zend_array_dup (spl_array_get_hash_table (intern )));
808
808
} /* }}} */
809
809
810
- static HashTable * spl_array_get_properties (zval * object ) /* {{{ */
810
+ static HashTable * spl_array_get_properties_for (zval * object , zend_prop_purpose purpose ) /* {{{ */
811
811
{
812
812
spl_array_object * intern = Z_SPLARRAY_P (object );
813
+ HashTable * ht ;
814
+ zend_bool dup ;
813
815
814
816
if (intern -> ar_flags & SPL_ARRAY_STD_PROP_LIST ) {
815
- if (!intern -> std .properties ) {
816
- rebuild_object_properties (& intern -> std );
817
- }
818
- return intern -> std .properties ;
817
+ return zend_std_get_properties_for (object , purpose );
818
+ }
819
+
820
+ /* We are supposed to be the only owner of the internal hashtable.
821
+ * The "dup" flag decides whether this is a "long-term" use where
822
+ * we need to duplicate, or a "temporary" one, where we can expect
823
+ * that no operations on the ArrayObject will be performed in the
824
+ * meantime. */
825
+ switch (purpose ) {
826
+ case ZEND_PROP_PURPOSE_ARRAY_CAST :
827
+ dup = 1 ;
828
+ break ;
829
+ case ZEND_PROP_PURPOSE_VAR_EXPORT :
830
+ case ZEND_PROP_PURPOSE_JSON :
831
+ dup = 0 ;
832
+ break ;
833
+ default :
834
+ return zend_std_get_properties_for (object , purpose );
819
835
}
820
836
821
- return spl_array_get_hash_table (intern );
837
+ ht = spl_array_get_hash_table (intern );
838
+ if (dup ) {
839
+ ht = zend_array_dup (ht );
840
+ } else {
841
+ GC_ADDREF (ht );
842
+ }
843
+ return ht ;
822
844
} /* }}} */
823
845
824
846
static HashTable * spl_array_get_debug_info (zval * obj , int * is_temp ) /* {{{ */
@@ -2013,7 +2035,7 @@ PHP_MINIT_FUNCTION(spl_array)
2013
2035
spl_handler_ArrayObject .has_dimension = spl_array_has_dimension ;
2014
2036
spl_handler_ArrayObject .count_elements = spl_array_object_count_elements ;
2015
2037
2016
- spl_handler_ArrayObject .get_properties = spl_array_get_properties ;
2038
+ spl_handler_ArrayObject .get_properties_for = spl_array_get_properties_for ;
2017
2039
spl_handler_ArrayObject .get_debug_info = spl_array_get_debug_info ;
2018
2040
spl_handler_ArrayObject .get_gc = spl_array_get_gc ;
2019
2041
spl_handler_ArrayObject .read_property = spl_array_read_property ;
0 commit comments