Re: Null Coalesce Operator and Undefined Indexes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux