6

$a = -1;
if ($a) {
return true;
}
else {
return false;
}

true or false?

Comments
  • 3
    Depends on the language.
  • 1
    @darksideplease Due to the '$' you could guess it's PHP :D
  • 2
    Oh and it's true 😊
    Just 0 ist considered false, any others numbers converted to a boolean value are considered true, even negative numbers :D
  • 2
    Wouldn't it be easier to say
    return (bool) $a
    ?
  • 0
    @SZenC yes sure, though a conversion ist not necessary I think :D
  • 2
    @DataSec Removing the casting would cause the function signature to change, it would then output a number in stead of a boolean. But then again, this code is weird anyway
  • 2
    @SZenC Oh yea you are right I was thinking of a return type in a function for example, but its necessary in PHP, as you just explained 😊
  • 0
    @DataSec I am actively ignoring PHP.
  • 0
  • 0
    True
  • 0
    @DataSec Everybody always points out how bad it is and how bad most of the programs written php are.
Add Comment