Skip to content

TraceableEventDispatcher reset should instantiate SplObjectStorage #29703

Closed
@lievertz

Description

@lievertz

Symfony version(s) affected: 3.4.x-dev (from #29411)

Description
TraceableEventDispatcher was rewritten to use callStack as SplObjectStorage instead of array, but #reset() still assigns callStack to array(), which throws error at line 268 with 'Call to a member function attach() on array' on next call to dispatch().

How to reproduce
Just grab the TraceableEventDispatcher, call reset(), and call dispatch() on anything.

<?php
class BugReproduceTest extends \Codeception\Test\Unit
{
    /**
     * @group repro
     */
    public function testReproduce()
    {
        $dispatcher = $this->getModule( 'Symfony' )->grabService( 'debug.event_dispatcher' );
        $dispatcher->reset();
        $dispatcher->dispatch( 'kernel.request' );
    }
}

Possible Solution
Suggest a simple change
from (starting line 222):

    public function reset()
    {
        $this->callStack = array();
    }

to (starting line 222)

    public function reset()
    {
        $this->callStack = new \SplObjectStorage();
    }

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions