I have the following piece of code in my project, and that a few times:
$this->uniqueSessionKey = $settings->get('uniqueSessionKey') ? $settings->get('uniqueSessionKey') : $_SERVER['HTTP_USER_AGENT'] . time();
I was wondering if there's a better way of writing this, especially the part where it checks if
$settings->get(...) is not false and then uses the previously checked value. As it uses a database connection it's probably not very efficient checking for the same thing twice.
Is there a better way of writing this? I'm already using the shortest if-else that I'm aware of.
If it's not possible, I will put the
$settings->get(...) in a variable anyway, and then check if it's false. I've tried using
|| but that returned false (?) so I probably did that wrong.
Note that I don't want to check it for multiple values, so I don't need to use