There is no equivalent for this method in the new extension, so instead use…
<?php
if ($id instanceof \MongoDB\BSON\ObjectID
|| preg_match('/^[a-f\d]{24}$/i', $id)
) {
…
}
?>
PHP - Manual: MongoId::isValid
2024-11-14
(PECL mongo >= 1.5.0)
MongoId::isValid — Check if a value is a valid ObjectId
This extension that defines this method is deprecated. Instead, the MongoDB extension should be used. There is no equivalent for this method in the new extension.
This method may be used to check a variable before passing it as an argument to MongoId::__construct().
value
The value to check for validity.
Returns TRUE
if value
is a
MongoId instance or a string consisting of exactly 24
hexadecimal characters; otherwise, FALSE
is returned.