Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Event listeners order

Hello everybody. Let's try to execute the following code:

$em = new \Phalcon\Events\Manager();
$em->attach('component:test', function ($e) {echo '1 ';});
$em->attach('component:test', function ($e) {echo '2 ';});
$em->attach('component', function ($e) {echo '3 ';});
$em->attach('component', function ($e) {echo '4 ';});
$em->fire('component:test', $this);

The expected result - 1 2 3 4.
But in fact it's - 3 4 1 2

It seems like component listeners executed before concrete event listeners.
That behaviour is not documented and the order of listeners becomes unclear with such logic, as for me.


Thanks for the answer, it may help me if I suggest to make a pull-request :) Nevertheless I think that behaviour should be documented, or changed to make the order of listeners more predictable

Events attached directly to an event name are executed after the components that aren't attached directly.