Bug #54367edit

Bug #54367 (Use of closure causes Problem in Array Access) prevents closures from working if they implement ArrayAccess. Pimple, the dependency injection container used in this library, makes heavy use of ArrayAccess. In several places, Elasticsearch-php closes over the pimple object itself to return a new function (providing a lightweight factory type method, without actually creating dedicated factory objects).

For example, this code would trigger bug #54367:

private function setConnectionObj()
{
    $this->dic['connection'] = function ($dicParams) {
        return function ($host, $port = null) use ($dicParams) {   // <--- This is the problem
            return new $dicParams['connectionClass'](
                $host,
                $port,
                $dicParams['connectionParamsShared'],
                $dicParams['logObject'],
                $dicParams['traceObject']
            );
        };
    };
}

Notice how return function ($host, $port = null) use ($dicParams) captures $dicParams (which is a Pimple object) in the closure.