View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017325 | mantisbt | code cleanup | public | 2014-05-12 05:07 | 2019-01-11 06:39 |
Reporter | grangeway | Assigned To | dregad | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | closed | Resolution | fixed | ||
Product Version | 1.2.16 | ||||
Target Version | 1.3.2 | Fixed in Version | 1.3.2 | ||
Summary | 0017325: helper_array_transpose should always return an array | ||||
Description | function helper_array_transpose( $p_array ) { The purpose of helper_array_transpose is documented to only take an input array (and indeed that is how we use it). We should adjust the function to always return an array - if passed null, we should return an empty array(). This allows the result to be passed directly into a foreach loop for example | ||||
Tags | No tags attached. | ||||
While the proposed change is fine for the case of $p_array == NULL (which is how it's currently used in bug_report.php), what about when it's some other value (e.g. bug_file_add.php uses -1). Also, how would you recommend handling the case of $p_array being a one-dimentional array ? Would you also return an empty array in this case ? Anyway, that's an API change/improvement, which is independent from the original fix. |
|
we do if ( !is_array( $p ) return $p - so one-dimensional array isn't going to hit that code path. I think in the case of one-dimensional array we currently return the original array? Moving forwards, I'd like to simplify our input/output to functions to be stricter on the data types - hence my suggestion regarding array(); |
|
Reopened following revert of MantisBT master-1.3.x eaa7286a cproensa Sep 03 20:29 |
|
MantisBT: master-1.3.x eaa7286a 2016-09-01 06:16 Details Diff |
helper_array_transpose() only handles bidimentional arrays Fixes 0017325 |
Affected Issues 0017325 |
|
mod - core/helper_api.php | Diff File | ||
MantisBT: master-1.3.x fb35359b 2016-09-01 06:16 Details Diff |
helper_array_transpose() only handles bidimensional arrays The function now triggers an error if the input array is not bidimensional. This fixes the issues introduced by earlier attempt (see commit eaa7286a87ec5bce9320807c18df542427989f68, reverted in dd39f53bb009f1172a312c6ccbb8d4dbd6984e21). The original did not properly handle associative arrays, and had faulty logic causing the function to always fail for arrays. It also did not detect some "non-square" arrays (i.e. with the 1st element as array and the 2nd as scalar). Fixes 0017325 |
Affected Issues 0017325 |
|
mod - core/helper_api.php | Diff File | ||
MantisBT: master-1.3.x dd39f53b 2016-09-03 10:55 Details Diff |
Revert "helper_array_transpose() only handles bidimentional arrays" This reverts commit eaa7286a87ec5bce9320807c18df542427989f68. |
Affected Issues 0017325 |
|
mod - core/helper_api.php | Diff File |