php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54970 SplFixedArray::setSize() isn't resizing
Submitted: 2011-06-01 15:25 UTC Modified: 2011-06-02 02:40 UTC
From: marco dot paulo dot lopes at gmail dot com Assigned: felipe (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marco dot paulo dot lopes at gmail dot com
New email:
PHP Version: OS:

 

 [2011-06-01 15:25 UTC] marco dot paulo dot lopes at gmail dot com
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"
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-02 02:40 UTC] felipe@php.net
-Summary: SplFixedArray.setSize ambiguous treatment of existing values +Summary: SplFixedArray::setSize() isn't resizing
 [2011-06-02 02:40 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=311721
Log: - Fixed bug #54970 (SplFixedArray::setSize() isn't resizing)
 [2011-06-02 02:40 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2011-06-02 02:40 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:50 UTC] laruence@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df4c4a9e7f4e11fec8797d8c9c1141ccc6e8633e
Log: - Fixed bug #54970 (SplFixedArray::setSize() isn't resizing)
 [2012-07-24 23:41 UTC] rasmus@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df4c4a9e7f4e11fec8797d8c9c1141ccc6e8633e
Log: - Fixed bug #54970 (SplFixedArray::setSize() isn't resizing)
 [2013-11-17 09:37 UTC] laruence@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df4c4a9e7f4e11fec8797d8c9c1141ccc6e8633e
Log: - Fixed bug #54970 (SplFixedArray::setSize() isn't resizing)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC