After upgrade from Mongo 4.x to 8.x on old server, bsonSerialize() compatibility issue

If you upgrade from Mongo 4.x to 8.x and MongoDB stops working with:

PHP Fatal error: Declaration of MongoDB\Model\BSONArray::bsonSerialize() must be compatible with MongoDB\BSON\Serializable::bsonSerialize(): stdClass|MongoDB\BSON\Document|MongoDB\BSON\PackedArray|array

Don’t use php8.3-mongodb, but rather PECL and do this:

pecl install mongodb-1.21.0

https://www.mongodb.com/community/forums/t/php-mongodb-2-0-0-bsonarray-bsonserialize-error-bsonarray-php-on-line-74/318628/3

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top