php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch getarraycopy-skip-protected-and-private for SPL related Bug #55211

Patch version 2011-07-24 04:17 UTC

Return to Bug #55211 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: laruence@php.net

Index: ext/spl/spl_array.c
===================================================================
--- ext/spl/spl_array.c	(revision 313645)
+++ ext/spl/spl_array.c	(working copy)
@@ -719,10 +719,29 @@
 SPL_METHOD(Array, getArrayCopy)
 {
 	zval *object = getThis(), *tmp;
+	HashTable *origin;
 	spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
-    
-    array_init(return_value);
-	zend_hash_copy(HASH_OF(return_value), spl_array_get_hash_table(intern, 0 TSRMLS_CC), (copy_ctor_func_t) zval_add_ref, &tmp, sizeof(zval*));
+
+	origin = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
+
+	array_init(return_value);
+
+	if (zend_hash_num_elements(origin)) {
+		char *key;
+		long  key_len, num_key;
+		zval **tmp;
+		HashPosition pos;
+		for (zend_hash_internal_pointer_reset_ex(origin, &pos);
+				zend_hash_get_current_key_ex(origin, &key, (uint *)&key_len, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
+				zend_hash_move_forward_ex(origin, &pos)
+			) {
+			/* skip protected/private properties */
+			if (key[0] && (zend_hash_get_current_data_ex(origin, (void **)&tmp, &pos) == SUCCESS)) {
+				zval_add_ref(tmp);
+				zend_hash_update(Z_ARRVAL_P(return_value), key, key_len, tmp, sizeof(zval *), NULL);
+			}
+		}
+	}
 } /* }}} */
 
 static HashTable *spl_array_get_properties(zval *object TSRMLS_DC) /* {{{ */
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Apr 10 19:01:24 2020 UTC