$a = isset ($a)? $a:false
This is the best way for doing so without warnings
Question
Another micro-optim question. What is the php best way to set variable like in javascript existing or new value
var a = a || false
using
$a = $a || false;
we get error notice abour undefined variable $a
. This variable may or may not be set in previous programm part. (Due plug-ins.) It can be done with extra condition before. Stg like if isset(...
The question is does elegant 1 row solution exists?
Solution
$a = isset ($a)? $a:false
This is the best way for doing so without warnings
OTHER TIPS
Solution exists:
In general:
$a = isset($a) ? $a : false;
Some example with handling $_GET
array.
$a = isset($_GET['someParam']) ? $_GET['someParam'] : false;
You can use everything instead of $a
or $_GET['someParam']
.