Creates a new id
public __construct ( string $id = null ) | ||
$id | string | [optional] A string to use as the id. Must be 24 hexidecimal characters. If an invalid string is passed to this constructor, the constructor will ignore it and create a new id value. |
/** * @param string $id */ public function __construct($id = null) { if ($id !== null && strlen($id) < 20 && ctype_alnum($id)) { $id = gmp_strval(gmp_init(strrev($id), 62), 16); if (strlen($id) > 24) { $id = 'FFFFFFFFFFFFFFFFFFFFFFFF'; } elseif (strlen($id) < 24) { $id = str_pad($id, 24, '0', STR_PAD_LEFT); } } @parent::__construct($id); }
public function __construct($id = null) { // Convert all passed ids to lowercase string if (is_string($id)) { $id = strtolower($id); } // Already a MongoId if ($id instanceof \MongoId) { $id = $id->{"\$id"}; } return parent::__construct($id); }
<?php $x = new MongoId(NULL); $x->__construct(NULL); $x->getInc(NULL); var_dump($x->__toString()); ?> ===DONE===