it
function doThings(){ if($oh){ return $oh; } return false; }
equal to this
function doThings(){ if($oh){ return $oh; }else{ return false; } }
Thank!
Yes, both do the same. Personally, I prefer to exit the function in the same place. eg.
function doThings(){ $flag = false; if($oh){ $flag = $oh; } return $flag; }
In the scenario described above, Yes . Or it should work fine. I prefer the first method, less typing and that's it.
, .
:
function doThings(){ return $oh; }
, PHP "false", false, $oh, false, .
$oh
function doThings(){ return $oh ? $oh : false; }
, , , ... , .
Quicktip:
function do() { if (!$oh) { return false; } return $oh; }
, , . , ( ). .
function doThings() { return $oh ?: false; }
PHP:
function doThings() { return $oh ? $oh : false; }
, :
function doThings() { $oh = null; // set to some default; // do stuff return $oh; }
, . - (, )
function doSomething() { $return_value = false; if($oh) { $return_value = true; } return $return_value; }
. return , , .
, - .
, return , , , , . , , PHP .