Home » Structures » Structures_DataGrid_DataSource_Array » Bug #9914
Incorrect array index assumption
Details
| Submitted | 2007-01-22 15:12 UTC |
|---|---|
| From | rjbarbour at gmail dot com |
| Assigned | wiesemann |
| Status | Closed |
| Package | Structures_DataGrid_DataSource_Array |
| PHP Version | 5.0.5 |
| OS | XP 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.