I am often in a situation when the variable can be object
or null
.
When I put data into the database I have to stick with something like this:
// @var User|null $user
$data['id_user'] = $user!==null ? $user->getId() : null;
Is there any way to shorthen this? I am aware of ??
, but this is somewhat opposite.
I am using PHP 7.1.