I created my own logic for evaluating short circuits, unfortunately, this does not seem like fast javascripts syntax, but maybe this is a solution that may come in handy:
$short_circuit_isset = function($var, $default_value = NULL) { return (isset($var)) ? : $default_value; }; $return_title = $short_circuit_isset( $_GET['returntitle'], 'God'); // Should return type 'String' value 'God', if get param is not set
I canβt remember where I got the following logic from, but if you do the following:
(isset($var)) ? : $default_value;
You can skip the need to write the true condition variable again after the question mark, for example:
(isset($super_long_var_name)) ? $super_long_var_name : $default_value;
As a very important observation when using the Ternary Operator in this way, you will notice that if a comparison is made, it will simply convey the value of this comparison, since there is more than just a single variable. For example:
$num = 1; $num2 = 2; var_dump( ($num < $num2) ? : 'oh snap' ); // outputs bool 'true'
Perspective Nov 30 '15 at 17:01 2015-11-30 17:01
source share