Function that only returns false returns nothing

user2264061
function return_true () {
    return true;
}

function return_false () {
    return false;
}

echo return_true(); //outputs 1
echo return_false(); //outputs nothing

why can't I echo out return_false and get 0 ? Apologies if this has been asked before but I didn't find anything that answers this question. Note: I am not saying this is something that needs to be done, I was just messing around with bools in PHP and found this odd.

DKSan

Use var_dump() instead of echo and you will get your desired result.

echo will output a string and a boolean false echoed as a string will always be nothing / empty

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related