alcaeus / mongo-php-adapter

:link: Adapter to provide ext-mongo interface on top of mongo-php-library
MIT License
463 stars 125 forks source link

PHP 8.2 support #312

Closed kirkmadera closed 2 months ago

kirkmadera commented 2 months ago

Can this be updated for PHP 8.2 support?

MongoId implements the Serializable interface, which is deprecated. Implement serialize() and unserialize() instead (or in addition, if support for old PHP versions is necessary)

This library is required by https://github.com/perftools/xhgui-collector at the moment and there is not another alternative. The xhgui-collector library could also get updated to use the mongodb extension, but until this, this seems like an easier fix.

In local testing, I was able to get past this by just remove the implements Serializable definition.

kirkmadera commented 2 months ago

I solved this locally for now with a custom error handler that looks for this specific error and ignores it.

$previousErrorHandler = set_error_handler(
    static function (int $errNo, string $errstr, string $errFile, int $errLine) use (&$previousErrorHandler): bool
    {
        if (str_starts_with($errstr, 'MongoId implements the Serializable')) {
            return true;
        }

        // Handle specific scenarios
        return $previousErrorHandler !== null && $previousErrorHandler(...func_get_args());
    }
);
kirkmadera commented 2 months ago

To further expand on this, the mongodb saver is deprecated in the xhgui-collector library. After switching to the UploadSaver, the custom error handler is no longer necessary.

Either way, this seems very low priority as there are workarounds.

alcaeus commented 2 months ago

I'm just going to link this here: https://github.com/alcaeus/mongo-php-adapter/issues/308. Please note that there will be a 2.0 version of the MongoDB driver in the near future, which will require PHP 8.1 and newer. Like I've stated in the linked ticket, I will not be updating this library.

In case you haven't realised, ext-mongo is dead, and so is ODM 1.x for which I originally created this library. If you've prioritised updating to newer PHP versions without updating the MongoDB driver, now is the time to do so. It will not get easier over time.