From:             
Operating system: 
PHP version:      5.3.6
Package:          SPL related
Bug Type:         Bug
Bug description:SplFixedArray.setSize ambiguous treatment of existing values

Description:
------------
---

>From manual page: http://www.php.net/splfixedarray.setsize

---



When resizing an SplFixedArray using the setSize method, values from the
deleted 

indexes behave strangely.



Test script:
---------------
The following piece of code:



<?php

$fa = new SplFixedArray(2);

$fa[0] = 'Hello';

$fa[1] = 'World';

$fa->setSize(3);

var_dump($fa);

$fa[2] = '!';

$fa->setSize(1);

var_dump($fa);

?>



Outputs: 



object(SplFixedArray)#1 (3) {

  [0]=>

  string(5) "Hello"

  [1]=>

  string(5) "World"

  [2]=>

  NULL

}

object(SplFixedArray)#1 (3) {

  [0]=>

  string(5) "Hello"

  [1]=>

  string(5) "World"

  [2]=>

  NULL

}



While the following piece of code:



<?php

$fa = new SplFixedArray(2);

$fa[0] = 'Hello';

$fa[1] = 'World';

$fa->setSize(3);

$fa[2] = '!';

var_dump($fa);

$fa->setSize(1);

var_dump($fa);

?>



Outputs this:



object(SplFixedArray)#1 (3) {

  [0]=>

  string(5) "Hello"

  [1]=>

  string(5) "World"

  [2]=>

  string(1) "!"

}

object(SplFixedArray)#1 (3) {

  [0]=>

  string(5) "Hello"

  [1]=>

  string(5) "World"

  [2]=>

  string(1) "!"

}

Expected result:
----------------
I would expect to see the same in either of the above presented cases, and
it 

should be an array with the new size that was specified using setSize:



object(SplFixedArray)#1 (1) {

  [0]=>

  string(5) "Hello"

}




-- 
Edit bug report at http://bugs.php.net/bug.php?id=54970&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54970&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54970&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54970&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54970&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54970&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54970&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54970&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54970&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54970&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54970&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54970&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54970&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54970&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54970&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54970&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54970&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54970&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54970&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54970&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54970&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54970&r=mysqlcfg

Reply via email to