Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Zend\Stdlib\PriorityList reports incorrect count when inserting duplicate items #8

Closed
dankobiaka opened this issue Jun 4, 2015 · 1 comment

Comments

@dankobiaka
Copy link
Contributor

See https://github.com/zendframework/zf2/blob/master/library/Zend/Stdlib/PriorityList.php#L66

Zend\Stdlib\PriorityList increments $this->count every single time insert($name, $value) is called, regardless of whether $name already exists.

This results in an incorrect count being calculated when inserting items with the same $name.

For example, to see this issue:

$list = new \Zend\Stdlib\PriorityList();
$list->insert('test', 'value');
$list->insert('test', 'value');
$list->insert('test', 'value');

print sprintf("List count: %d\n", count($list));
print sprintf("Array count: %d\n", count($list->toArray()));

$list->remove('test');

print sprintf("List count after removing 1 item: %d\n", count($list));
print sprintf("Array count after removing 1 item: %d\n", count($list->toArray()));

// -- outputs: --
// List count: 3
// Array count: 1
// List count after removing 1 item: 2
// Array count after removing 1 item: 0
@weierophinney
Copy link
Member

Fixed with #9.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants