I am defining a database model property like this.
class GuestList extends DatabaseModel
{
protected static $table = 'GuestLists';
public $ID;
public $EventName;
public \DateTime $EventDateTime;
}
But its throwing a fatal error. because there are already some data in that table and for some row the value in the EventDateTime is NULL. If i dont set \DateTime the error goes away. But is there any way so the fiels also accepts Null value?
>Solution :
Just add nullable type hint by prefixing ? to your other type hint:
class GuestList extends DatabaseModel
{
protected static $table = 'GuestLists';
public $ID;
public $EventName;
public ?\DateTime $EventDateTime;
}