PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Structures » Structures_DataGrid_DataSource_Array » Bug #9914

Incorrect array index assumption

Details

Submitted2007-01-22 15:12 UTC
Fromrjbarbour at gmail dot com
Assignedwiesemann
StatusClosed
PackageStructures_DataGrid_DataSource_Array
PHP Version5.0.5
OSXP SP2
Roadmaps(Not assigned)

Comments

[2007-01-22 15:12 UTC] rjbarbour at gmail dot com

Description:
------------
The array $_ar may have integer indexes. The script assume, on line 120 of Array.php, that the first element of the array will be at $_ar[0]. This can be an incorrect assumption.
See example below.

Test script:
---------------
$my_array = array( 5 => 'five', 3 => 'three' );
$datagrid->bind($my_array);
//$this->_ar[0] on line 120 of Array.php will evaluate to NULL

Expected result:
----------------
No warning.

Actual result:
--------------
Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\<my_path>\PEAR\pear\Structures\DataGrid\DataSource\Array.php on line 120

[2007-01-22 15:13 UTC] rjbarbour at gmail dot com

changed my email address

[2007-01-23 22:23 UTC] rjbarbour at gmail dot com

Access to key 0 may be invalid if the first element of the shiny new array is unset:

eg:

$my_array = array(
array( 'name' => 'Alice', 'address' => 'foo' ),
array( 'name' => 'Bob', 'address' => 'bar')
array( 'name' => 'Charlie', 'address' => 'quxx')
);
unset($my_array['0']);
/*
Array now looks like this:
array(
1 => array( 'name' => 'Bob', 'address' => 'bar')
2 => array( 'name' => 'Charlie', 'address' => 'quxx')
)
*/
$datagrid->bind($my_array);

If $my_array is re-indexed with array_merge() then Array.php will not complain.

I don't think it should be necessary to do this.