Say I have this:
$username = (string) $inputs['username'] ?? null;
If $inputs['username']
is set then I want it to cast to string
. If it's not set then $username
should be null
.
However, at the moment if $inputs['username']
is not set it will be an empty string instead of null.
How can I fix this? Or is this intentional behaviour?
??
to cut down on theisset()
code you'd normally use with?:
because of working on an application where types need to be strictly enforced. – Jacobean$username = (string?) $inputs['username'] ?? null
– Eosin