php教程

MongoId::isValid

(PECL mongo >= 1.5.0)

MongoId::isValidCheck if a value is a valid ObjectId

说明

public static MongoId::isValid ( mixed $value ) : bool

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.

User Contributed Notes

le6o 14-Jul-2016 02:57
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)
) {
 
...
}
?>

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788