diff options
author | Xinchen Hui <laruence@php.net> | 2013-02-24 12:58:39 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@php.net> | 2013-02-24 12:58:39 +0800 |
commit | d24ac6953ec8ca147243363eeacc8772d265b6cc (patch) | |
tree | 2181db4b99ad20b1278a18248f75b0d3746e6ea5 | |
parent | 064c62e4cf078cf08a40478dfe0e64bd51789e57 (diff) | |
parent | 1b58bd39a637e9ec4ea9e95903b74aefdbd1b596 (diff) | |
download | php-git-d24ac6953ec8ca147243363eeacc8772d265b6cc.tar.gz |
Merge branch 'PHP-5.3' into PHP-5.4
Conflicts:
ext/spl/spl_fixedarray.c
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/spl/spl_fixedarray.c | 25 | ||||
-rw-r--r-- | ext/spl/tests/bug64264.phpt | 29 |
3 files changed, 45 insertions, 10 deletions
@@ -24,6 +24,7 @@ PHP NEWS (Johannes) - SPL: + . Fixed bug #64264 (SPLFixedArray toArray problem). (Laruence) . Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS). (patch by kriss@krizalys.com, Laruence) . Fixed bug #64106 (Segfault on SplFixedArray[][x] = y when extended). diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index c0d5a35a23..ebc4e341a6 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -627,22 +627,27 @@ SPL_METHOD(SplFixedArray, count) */ SPL_METHOD(SplFixedArray, toArray) { - zval *ret, *tmp; - HashTable *ret_ht, *obj_ht; + spl_fixedarray_object *intern; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) { return; } - ALLOC_HASHTABLE(ret_ht); - zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0); - ALLOC_INIT_ZVAL(ret); - Z_TYPE_P(ret) = IS_ARRAY; - obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC); - zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - Z_ARRVAL_P(ret) = ret_ht; + intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_ZVAL(ret, 1, 1); + array_init(return_value); + if (intern->array) { + int i = 0; + for (; i < intern->array->size; i++) { + if (intern->array->elements[i]) { + zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL); + Z_ADDREF_P(intern->array->elements[i]); + } else { + zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL); + Z_ADDREF_P(EG(uninitialized_zval_ptr)); + } + } + } } /* }}} */ diff --git a/ext/spl/tests/bug64264.phpt b/ext/spl/tests/bug64264.phpt new file mode 100644 index 0000000000..e7b695bd82 --- /dev/null +++ b/ext/spl/tests/bug64264.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #64264 (SPLFixedArray toArray problem) +--FILE-- +<?php +class MyFixedArray extends \SplFixedArray { + protected $foo; + protected $bar; +} + +$myFixedArr = new MyFixedArray(1); +$myFixedArr[0] = 'foo'; +$myFixedArr->setSize(2); +$myFixedArr[1] = 'bar'; +$myFixedArr->setSize(5); +$array = $myFixedArr->toArray(); +$array[2] = "ERROR"; +$array[3] = "ERROR"; +$array[4] = "ERROR"; +unset($array[4]); +$myFixedArr->setSize(2); + +print_r($myFixedArr->toArray()); +?> +--EXPECTF-- +Array +( + [0] => foo + [1] => bar +) |