I am reviewing a partner php code and is like:
function query_db($form)
{
$result = (int)false;
try{
$sqlQuery = " SELECT id_user, id_access, name, email, status FROM users ";
$sqlQuery .= " WHERE id_access> 0 ";
if($form->get("limit")){
$sqlQuery .= " LIMIT ".$form->get("start")." , ".$form->get("registry");
}
$query = $this->db->query($sqlQuery);
return $query;
} catch (Exception $e) {
$result = (int)false;
}
return $result;
}
So at the very begining he uses $result = (int)false;
I was investigating this instruction and found:
A string is converted to false only if it is empty or if it contains the single character 0. If it contains any other data—even multiple zeros—it is converted to true.
When converted to a number or a string, a Boolean becomes 1 if it is true, and 0 otherwise.
So back to the question:
echo 0 + 1; // 1
echo false + 1; // 1
echo 0 > -1; // true
echo false > -1; // false
echo (int)false > -1; // true
So why in the world he casts it instead of using $result = 0;
I mean, I do not understand, maybe it has a deeper meaning and I am not seing this.
Thats why I ask your opinion.