0

I was learning about cookies and had made two varibles named $cookieSetzen and $cookieLöschen. I want to assign it value if the $_GET parameter is set or if not the varible should be FALSE. I wanted to do it in the short version of the if statement. My first version looked like this :

if (isset($_GET['cookieSetzen']) or isset($_GET['cookieLöschen']))
{
    $cookieSetzen = $_GET['cookieSetzen'] ? $_GET['cookieSetzen']:FALSE;
    $cookieLöschen = $_GET['cookieLöschen'] ? $_GET['cookieLöschen']:FALSE;
}

Then phpStorm said that there would be a version with ?? And this looks like this:

if (isset($_GET['cookieSetzen']) or isset($_GET['cookieLöschen']))
{
    $cookieSetzen = isset($_GET['cookieSetzen']) ?? FALSE;
    $cookieLöschen = isset($_GET['cookieLöschen']) ?? FALSE;
}

Now I'm not sure what exactly happens there, but I think it checks if the $_GET[] value is set and then assign it to the variable and if it's not set it assign FALSE. Is this true and are there improvements to make ?

anyone
  • 37
  • 4
  • You wouldn't want `$cookieSetzen = isset($_GET['cookieSetzen']) ?? FALSE;`. Just have the variable there. Otherwise you set it to TRUE, not the value, when it is set. `$cookieSetzen = $_GET['cookieSetzen'] ?? FALSE;` – user3783243 Feb 15 '22 at 20:59

0 Answers0