Problem on appending new identifier on EventManager #3685

Closed
tommas1988 opened this Issue Feb 6, 2013 · 2 comments

Projects

None yet

4 participants

@tommas1988

The source code of EventManager::addIdentifier() shows , it can not append new identifier when using array or Traversable type argument.
Sample Code:
$events = new Zend\EventManager\EventManager('testIdentifier');
$events->addIdentifiers(array('anotherIdentifier'));
var_dump($events->getIdentifiers());

Expected to return
array (size=2)
0 => string 'testIdentifier' (length=14)
1 => string 'anotherIdentifier' (length=17)

but actually return
array (size=1)
0 => string 'testIdentifier' (length=14)

It shouldn`t use '+' operator in EventManager::addIdentifier() when merge two array together and instead using array_merge function

@iquabius
Contributor

This is what happens:

    $events = new Zend\EventManager\EventManager('testIdentifier');

    var_dump($events->getIdentifiers());
    // you will get this:
    // array(size=1)
    //   0 => string 'testIdentifier' (length=14)

    // then you try to add another identifier as an array with the same key (0)
    $events->addIdentifiers(array(0 => 'anotherIdentifier'));
    // internally will happen:
    // array(0 => 'testIdentifier') + array(0 => 'anotherIdentifier')
    // and will result in
    // array(0 => 'testIdentifier')

I'm not sure, but it seems to me that the keys doesn't really matter, in this case array_merge() would be the solution.

@iquabius iquabius added a commit to iquabius/zf2 that referenced this issue Mar 13, 2013
@iquabius iquabius fix for issue #3685 25957e6
@iquabius
Contributor

This was fixed with #4022

@iquabius iquabius referenced this issue Nov 13, 2013
Closed

[ZF3] Clean event manager #5399

1 of 3 tasks complete
@gianarb gianarb pushed a commit to zendframework/zend-eventmanager that referenced this issue May 15, 2015
@iquabius iquabius fix for issue zendframework/zendframework#3685 9065c1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment