略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoId::isValid

2024-04-30

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.

add a note add a note

User Contributed Notes 1 note

up
8
le6o
2 years ago
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)
) {
 

}
?>

官方地址:https://www.php.net/manual/en/mongoid.isvalid.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3