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

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

Closed
dankobiaka opened this issue Jun 1, 2015 · 2 comments

Comments

@dankobiaka
Copy link

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
dankobiaka added a commit to dankobiaka/zf2 that referenced this issue Jun 1, 2015
Fixed issue with count calculation on insert

see zendframework#7562
@samsonasik
Copy link
Contributor

you should make pull request to zf repo, actually, now should be to https://github.com/zendframework/zend-stdlib

@dankobiaka
Copy link
Author

Logged at zendframework/zend-stdlib#8

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

Successfully merging a pull request may close this issue.

2 participants