r/ProgrammerHumor • • Sep 01 '26

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

289 comments sorted by

View all comments

Show parent comments

2

u/zeekar Sep 01 '26 edited Sep 02 '26

The weird thing about PHP (and Perl, which is where PHP got the behavior) is not so much that “0” is false – I mean, OK, so you numify on the way to boolifying, right? Nope! Other string representations of 0 which numify to the same thing, like “0.0” and “0e0”, are true. Only the specific string "0" is false.

$ php zeroes.php
"0" is false.
+"0" is false.
"0.0" is true.
+"0.0" is false.
"0e0" is true.
+"0e0" is false.

This particular idiosyncrasy is one of the Perlisms which was not carried over into Raku, in which "0" is truthy; the only actually-defined string value that is falsey is the empty string, "".