Skip to content

Commit 1b58bd3

Browse files
committed
Fixed bug #64264 (SPLFixedArray toArray problem)
1 parent fcd4b53 commit 1b58bd3

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? 2013, PHP 5.3.23
44

55
- SPL:
6+
. Fixed bug #64264 (SPLFixedArray toArray problem). (Laruence)
67
. Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
78
(patch by kriss@krizalys.com, Laruence)
89

ext/spl/spl_fixedarray.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,24 +611,26 @@ SPL_METHOD(SplFixedArray, count)
611611
SPL_METHOD(SplFixedArray, toArray)
612612
{
613613
spl_fixedarray_object *intern;
614-
zval *ret, *tmp;
615-
HashTable *ret_ht, *obj_ht;
616614

617615
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
618616
return;
619617
}
620618

621619
intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
622620

623-
ALLOC_HASHTABLE(ret_ht);
624-
zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0);
625-
ALLOC_INIT_ZVAL(ret);
626-
Z_TYPE_P(ret) = IS_ARRAY;
627-
obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC);
628-
zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
629-
Z_ARRVAL_P(ret) = ret_ht;
630-
631-
RETURN_ZVAL(ret, 1, 1);
621+
array_init(return_value);
622+
if (intern->array) {
623+
int i = 0;
624+
for (; i < intern->array->size; i++) {
625+
if (intern->array->elements[i]) {
626+
zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
627+
Z_ADDREF_P(intern->array->elements[i]);
628+
} else {
629+
zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
630+
Z_ADDREF_P(EG(uninitialized_zval_ptr));
631+
}
632+
}
633+
}
632634
}
633635
/* }}} */
634636

ext/spl/tests/bug64264.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #64264 (SPLFixedArray toArray problem)
3+
--FILE--
4+
<?php
5+
class MyFixedArray extends \SplFixedArray {
6+
protected $foo;
7+
protected $bar;
8+
}
9+
10+
$myFixedArr = new MyFixedArray(1);
11+
$myFixedArr[0] = 'foo';
12+
$myFixedArr->setSize(2);
13+
$myFixedArr[1] = 'bar';
14+
$myFixedArr->setSize(5);
15+
$array = $myFixedArr->toArray();
16+
$array[2] = "ERROR";
17+
$array[3] = "ERROR";
18+
$array[4] = "ERROR";
19+
unset($array[4]);
20+
$myFixedArr->setSize(2);
21+
22+
print_r($myFixedArr->toArray());
23+
?>
24+
--EXPECTF--
25+
Array
26+
(
27+
[0] => foo
28+
[1] => bar
29+
)

0 commit comments

Comments
 (0)