I have a simple document that has its ID:
/**
* @MongoDB\Id(strategy="increment")
* @Serializer\Since("2.0")
*/
protected $id;
and a property code
/**
* @var string
*
*/
protected $code;
I want that the code be generated based in the ID. So I am planning to define it in the constructor
public function __construct()
{
$this->code = (string)$this->id.(string)rand(0,1000);
}
My question is, as both are defined in the same php class, there would be any risk to define one based in another?
Any risk of the code ask for the id before it was defined? Or there is any better way of doing such thing?