Commit:    1b58bd39a637e9ec4ea9e95903b74aefdbd1b596
Author:    Xinchen Hui <larue...@php.net>         Sun, 24 Feb 2013 12:55:46 
+0800
Parents:   fcd4b5335a6df4e0676ee32e2267ca71d70fe623
Branches:  PHP-5.3

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=1b58bd39a637e9ec4ea9e95903b74aefdbd1b596

Log:
Fixed bug #64264 (SPLFixedArray toArray problem)

Bugs:
https://bugs.php.net/64264

Changed paths:
  M  NEWS
  M  ext/spl/spl_fixedarray.c
  A  ext/spl/tests/bug64264.phpt


Diff:
diff --git a/NEWS b/NEWS
index 0242cff..a298c55 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP                                                             
           NEWS
 ?? ??? 2013, PHP 5.3.23
 
 - SPL:
+  . Fixed bug #64264 (SPLFixedArray toArray problem). (Laruence)
   . Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
     (patch by kr...@krizalys.com, Laruence)
 
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 1d18afd..646c002 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -611,8 +611,6 @@ SPL_METHOD(SplFixedArray, count)
 SPL_METHOD(SplFixedArray, toArray)
 {
        spl_fixedarray_object *intern;
-       zval *ret, *tmp;
-       HashTable *ret_ht, *obj_ht;
 
        if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
                return;
@@ -620,15 +618,19 @@ SPL_METHOD(SplFixedArray, toArray)
 
        intern = (spl_fixedarray_object 
*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-       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;
-
-       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 0000000..e7b695b
--- /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
+)


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to