Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.85 KB

php-version-requirement.asciidoc

File metadata and controls

64 lines (52 loc) · 2.85 KB

PHP Version Requirement

Elasticsearch-php requires PHP version 5.3.9 or higher. There are two bugs in PHP below 5.3.9 which cause problems for this library.

Bug #54367

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.

Bug #43200

Bug #54367 was fixed in PHP 5.3.7, but we run into a different bug now. Bug #43200 (Interface implementation / inheritence not possible in abstract classes) now becomes a problem. In short, this bug occurs when you combine interfaces with concrete functions that are implemented in an abstract class.

Elasticsearch-php uses both interfaces and abstract classes in this manner. The interfaces provide a contract which all implementing objects must follow. This is important so that users can provide their own implementations for custom logic. By implementing the interface, they are guaranteed that their code will work correctly with the library.

Abstract classes are used to provide common functionality between different classes. For example, many Elasticsearch endpoints (search, get, index, etc) use similar URI parameters such as index and type. Instead of duplicating the code between all these classes, a single abstract class provides concrete implementations of the methods.

This means that the library runs into bug #43200 and is unusable until 5.3.9 when it was fixed.

Conclusion

In summary, PHP version 5.3.9 is the lowest compatible version. There are currently no plans to refactor the code to work around these two bugs.

PHP 5.3.9 is nearly two years old, and three new major versions (5.4, 5.5, 5.6) have been released since then. It is highly advised to upgrade to a newer major version, as a large number of bugs and performance improvements have been made during that time.