core
core copied to clipboard
MongoDB class existence check is out of date (with PHP7.0)
PHP MongoDB Driver has been updated in 2016, the old client class Mongo
is deprecated.
https://derickrethans.nl/new-drivers.html
But we still have this check in our core MongoDB class. Should we change it
if ( ! class_exists('Mongo'))
{
throw new \Mongo_DbException("The MongoDB PECL extension has not been installed or enabled");
}
The new check should be
if ( ! class_exists('Mongo') && ! class_exists('MongoDB\Client'))
{
throw new \Mongo_DbException("The MongoDB PECL extension has not been installed or enabled");
}
By the way, I think in the near future we should remove the ! class_exists('Mongo')
check too.
That is assuming the new MongoDB\Client class has exactly the same API als the old Mongo class. Is that the case? If not, the entire abstraction layer has to be rewritten, in which case you'd probably be better of using an external Mongo library.
Thank you for your reply. Currently we have to override the core class and override some methods to match with the new MongoDB Client. Actually some methods in the driver have been changed, and I think the best solution is to write a new Abstraction Driver or using an external library.
Is your class override complete? i.e. do all methods available work with the new MongoDB Client, or did you just override the methods you use?
I am willing to try and find the time to add the abstraction, but I am not a Mongo user, if you have complete code and willing to donate it?
currently we only override only some methods we used. But I think I will check remaining methods whether they need to be changed or not. I will share my complete code after I finish :)