Skip to content

Commit d24ac69

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
Conflicts: ext/spl/spl_fixedarray.c
2 parents 064c62e + 1b58bd3 commit d24ac69

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP NEWS
2424
(Johannes)
2525

2626
- SPL:
27+
. Fixed bug #64264 (SPLFixedArray toArray problem). (Laruence)
2728
. Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
2829
(patch by [email protected], Laruence)
2930
. Fixed bug #64106 (Segfault on SplFixedArray[][x] = y when extended).

ext/spl/spl_fixedarray.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,27 @@ SPL_METHOD(SplFixedArray, count)
627627
*/
628628
SPL_METHOD(SplFixedArray, toArray)
629629
{
630-
zval *ret, *tmp;
631-
HashTable *ret_ht, *obj_ht;
630+
spl_fixedarray_object *intern;
632631

633632
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
634633
return;
635634
}
636635

637-
ALLOC_HASHTABLE(ret_ht);
638-
zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0);
639-
ALLOC_INIT_ZVAL(ret);
640-
Z_TYPE_P(ret) = IS_ARRAY;
641-
obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC);
642-
zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
643-
Z_ARRVAL_P(ret) = ret_ht;
636+
intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
644637

645-
RETURN_ZVAL(ret, 1, 1);
638+
array_init(return_value);
639+
if (intern->array) {
640+
int i = 0;
641+
for (; i < intern->array->size; i++) {
642+
if (intern->array->elements[i]) {
643+
zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
644+
Z_ADDREF_P(intern->array->elements[i]);
645+
} else {
646+
zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
647+
Z_ADDREF_P(EG(uninitialized_zval_ptr));
648+
}
649+
}
650+
}
646651
}
647652
/* }}} */
648653

ext/spl/tests/bug64264.phpt

+29
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)