In PHP class. assignment has old code

Im currently in a server side scripting class. The instructors provide an example to compare to what you code with the assignment. I found out that their code is a little outdated. Im trying to redo this statement.

$investment = !isset($_COOKIE[‘investment’]) ? ’ ’ : $_COOKIE[‘investment’];

to this?:

$investment = !isset($_COOKIE[‘investment’]) ?? ’ ’ ;

Any help would be much appreciated. I have no background in coding.

What you have shown is not outdated.

What you are attempting is to use the Null coalescing operator in Php7. Since it is such a trivial thing I will refer you to the manual.

https://www.php.net/manual/en/migration70.new-features.php

Thank you. It was my instructor who told me it was “older” code. Hopefully, you can see why I am asking from other sources.

Technically, it is not the “newest” way it could be done, but there is nothing wrong with doing it that way.

Sponsor our Newsletter | Privacy Policy | Terms of Service