[PHP-DEV] Should "0" be false or not From: Andi Gutmans (andi <email protected>)
Date: 05/11/98

There's an issue we're still thinking about regarding the basic behavior of
PHP - whether "0" should be considered false or not. For those who
remembre, originally, early betas of PHP 3 considered "0" as false, and at
some point, we changed "0" to be considered true (since, after all, it's a
string that has one or more characters).
Now, Andi and I (and the rest of the core guys, perhaps) are wondering on
whether or not this should be the case. The main problem with "0" meaning
true is that you can't go through one full 'round trip' in the scalar type
conversions:

"" (string, false) <=> 0 (integer, false) <=> "0" (string, true)

It may be particularly signficant since all of the GET/POST/Cookie
variables are always of type string. As for some history background, since
the time when we changed "0" to mean true instead false, several features
were added to the language that remove the need for this change:
* each() was added, and provides an easy to use and reliable way to
traverse an entire array, which may contain empty strings or "0" strings in
both the keys and the values.
* The empty() statement was added, which provides an easy to use and a
reliable way to check if a variable is both set and 'non-empty' (if
(!empty($var))). This provides the 'standard' way of checking on whether a
form element coming from GPC has been filled out by the user or not.

For these reasons (mainly consistency, and the fact that there's now no
real reason not to do it) we think "0" should become false again. The main
issues are:
1. Do you guys agree with this? Consider the fact that there are only two
options, of making it mean false and making it mean true. Both approaches
have disadvantages and advantages, it just seems that considering it as
false has more advantages and less disadvantages (perhaps no disadvantages
at all?)
2. Another important question is how much of a downwards incompatability
nightmare this will cause. It'll be incompatible with PHP/FI 2, but that's
not a real big issue, since expression evaluation and truth-value has
changed a lot from 2.0 to 3.0 anyway. How many users of 3.0 relied on "0"
meaning true is the big question.

We intend to release RC5 today, so if you have any comments on this, fire
em ASAP :)

Andi & Zeev

---
Andi Gutmans <andi <email protected>>
Computer Science, Technion, Israel Institute of Technology
Web: http://andi.il.eu.org/ ICQ: 1568297 PGP: finger andi <email protected>
KeyID 62F5661D  fingerprint = 1A 87 A2 10 2F EF EF AB 47 E0 4D 42 F5 B5 49
AD