Summary | Restrict Comment To: groups lose group id when rendered |
Queue | Whups |
Type | Bug |
State | Resolved |
Priority | 1. Low |
Owners | chuck (at) horde (dot) org |
Requester | php (at) ideacode (dot) com |
Created | 04/04/2008 (6303 days ago) |
Due | |
Updated | 04/24/2008 (6283 days ago) |
Assigned | |
Resolved | 04/24/2008 (6283 days ago) |
Github Issue Link | |
Github Pull Request | |
Milestone | |
Patch | No |
Assigned to Chuck Hagenbuch
State ⇒ Resolved
Priority ⇒ 1. Low
New Attachment: issue.diff
Patch ⇒ No
Milestone ⇒
Queue ⇒ Whups
Summary ⇒ Restrict Comment To: groups lose group id when rendered
Type ⇒ Bug
State ⇒ Unconfirmed
this (I've annotated, as the code isn't commented):
// get all the groups I can access in array (group_id => label, ...) format
foreach (array_keys($mygroups) as $gid) {
$grouplist[$gid] = $groups->getGroupName($gid, true);
}
// sort those by name
asort($grouplist);
// tack "Any Group" onto the front
$grouplist = array_merge(array(0 => _("Any Group")), $grouplist);
// push into the form
$this->addVariable(_("Restrict Comment to:"), 'group', 'enum', true,
false, null, array($grouplist));
The intent of this code seems to be to create the drop-down for
restricting comments using the group ID (from the data tree) as the
option value and the group Name (also from the data tree) as the
option label.
However, array_merge() screws that up, because PHP 5 & PHP 4 re-index
the array, destroying the key association needed:
[bishop@predator staging]$ cat array_merge.php
<?php
$a = array (23 => 'Hello', '42' => 'World');
$a = array_merge(array (0 => 'I say, '), $a);
var_dump($a);
?>
[bishop@predator staging]$ php-5.2.5 array_merge.php
array(3) {
[0]=>
string(7) "I say, "
[1]=>
string(5) "Hello"
[2]=>
string(5) "World"
}
[bishop@predator staging]$ php-4.4.7 array_merge.php
array(3) {
[0]=>
string(7) "I say, "
[1]=>
string(5) "Hello"
[2]=>
string(5) "World"
}
My suggested patch (attached) is to replace array_merge() with the
plus operator.