User:Legoktm/0

https://github.com/php/php-src/blob/e1baef1835ba50e9183c603324c371acd01ec669/Zend/zend_operators.c#L629

Goal: submit an RFC asking for removal of this special case. '0' instead is truthy, while empty string is still falsey.

Tim says it should be fine to add a deprecation warning there.

Are there any other languages where '0' is falsey?

  • Perl also treats the string "0" as false. The exact string "0 but true" is used as an alternative by some builtin functions for returning true-valued numeric zeros, and is special-cased to not generate runtime warnings about non-numeric strings undergoing numeric conversions.
  • Tcl, as a stringly typed language, also treats the string "0" as false.

Would you want this feature in PHP today (without thinking about backwards-compatibility)?

Why did PHP introduce this behavior in the first place?

Can static linters stop this? E.g. phan, psalm? Why is that insufficient?

Examples of gotchas by experienced PHP programmers: