vendredi 23 juin 2017

PHP -0 is not <=0

Within a function X I am using the return value of another function Y. This Y sometimes returns the value -0. I am not able to catch this value with the following code:

if($y <= 0){
    return 'foo';
}else{
    return $y;
}

This should trigger the return 'foo' but this is not happening and I don't know why. gettype($y) returns double. Any explanations and/or solutions to catch this special case? int($y) doesn't do the trick.

Aucun commentaire:

Enregistrer un commentaire