Web lists-archives.com

Re: [PHP] Null Coalesce Operator and Undefined Indexes




On Sat, Nov 25, 2017 at 9:12 AM, Jennifer <jennifer@xxxxxxxxxxxxxxxxxxxx>
wrote:

>         I'm using PHP 7.1 now and just changed some code to use the Null
> Coalesce Operator, like so:
>
> $ua       = sanitize($_SERVER['HTTP_USER_AGENT']) ?? null;
>

You must use the ?? operator on the array access before passing it to your
sanitize() function.

     $ua       = sanitize($_SERVER['HTTP_USER_AGENT'] ?? null);

Cheers,
David