php-src
php-src copied to clipboard
string '0.0' evaluates to true
Description
Surely this is not a mistake, but I do not understand why it is so.
Consider the following code:
if (0) echo "int 0 is true" . "\n";
if ('0') echo "string '0' is true" . "\n";
if (0.0) echo "float 0.0 is true" . "\n";
if ('0.0') echo "string '0.0' is true" . "\n";
Why does the string '0.0' evaluate to true, when its logical value would be false? The string '0' evaluates to false. Why is the same not true for '0.0'?
https://3v4l.org/ZNhbM
PHP Version
PHP 7.X, 8.X
Operating System
All
Well, that's just long standing behavior; back then it was decided to treat "0" and "" as false, but no other strings.
Anyhow, such questions are better asked on StackOverflow etc. :)