函数名:MongoDB\BSON\Binary::__construct()
适用版本:PHP 5 >= 5.6.0, PHP 7, PECL mongodb >= 1.0.0
用法:该函数用于创建一个新的Binary对象,用于表示二进制数据。
语法:public MongoDB\BSON\Binary::__construct(string $data, int $type)
参数:
返回值:返回一个新的MongoDB\BSON\Binary对象。
示例:
$data = "Hello, World!";
$type = MongoDB\BSON\Binary::TYPE_GENERIC;
$binary = new MongoDB\BSON\Binary($data, $type);
var_dump($binary);
输出:
object(MongoDB\BSON\Binary)#1 (2) {
["data":"MongoDB\BSON\Binary":private]=>
string(13) "Hello, World!"
["type":"MongoDB\BSON\Binary":private]=>
int(0)
}
以上示例创建了一个包含字符串"Hello, World!"的Binary对象,并指定了类型为通用类型。可以根据需要修改$data和$type参数来创建不同类型的Binary对象。