Search code examples
phpnull-coalescing-operator

Null Coalesce Operator with a null last operand


It works fine and doesn't cause problem

echo $formErrorBag[ 'email' ] ?? null

But is it an accepted practice? Never saw an example of this used with null.


Solution

  • It's completely legal, and accepted. It's a pretty easy and elegant way to avoid raising an E_NOTICE if $formErrorBag doesn't have an 'email' key.