Was there a change in the API from Ver 1.21.0
to 2.0.0
of the library that broke backwards compatibility or is this a bug?
Yes, which is why we released these changes as 2.0.0 as opposed to 1.22.0. More specifically, the previous tentative return types were changed to be definitive, which is a BC break and hence only done in 2.0.0.
The issue that you ran into isn’t with composer, but rather with PECL. When you run pecl install mongodb
, PECL will pick the latest release to install, which as of this writing is 2.0.0. This means that you’re using the new driver with the old library version, which isn’t compatible. Depending on where you run composer install
or composer update
and how you deploy the files, composer doesn’t have a chance of catching the error. For example, if you run composer update
on a system with ext-mongodb
1.21 installed, composer will pick version 1.21 of the library. If you have ext-mongodb
2.0 installed, composer will pick version 2.0 of the library. So, if you copy the files to your server but have a different extension version installed, things will be broken, which is what I suspect happened here.
I don’t know how you managed to get nested vendor directories, so I can’t comment on that.
another good reason to package all files and not rely on 3rd party web-installers
That won’t do you any good here, as the issue wasn’t composer, but pecl
. The PHP Foundation is currently leading an effort to replace PECL with a tool called pie built on top of composer, which will allow more flexibility when choosing extension versions to install. If you use PECL, you’ll have to specify an exact version to install:
pecl install mongodb-1.21.0
pecl install mongodb-2.0.0
Without the exact version, you can’t be sure which version will be installed and it will depend on timing. Going forward, we will upload 1.x releases first, followed by 2.x releases, so that the latest version will always be a 2.x version, but there will be a short window where PECL could install a 1.x release just before we upload a 2.x release. On the other hand, if you use pie
, you can use version constraints like in composer.json:
php pie.phar install mongodb/mongodb-extension:^1.21
php pie.phar install mongodb/mongodb-extension:^2.0
The advantage is that you don’t have to update your provisioning scripts every time a new version is released, but you will receive backward compatible updates automatically. Please be aware that pie is still in active development and may contain bugs. We have tested the driver installation and it works so far, but changes in pie could result in short-term breakage.
Last but not least, we follow Semantic Versioning for our driver releases, so we won’t release a 2.1 version of the driver that requires you to make changes in order to continue working correctly. A 3.0 release however will once again contain BC breaks. That said, we currently don’t have any plans for a 3.0 release with breaking changes. You can also continue using 1.21, as we’ll be providing bug fixes for the 1.x release line for another year before this version becomes end-of-life and we only support 2.x releases.