Re: [RFC] Saner string to number comparisons
| From: | Claude Pache | Date: | Wed, 27 Feb 2019 08:44:13 +0000 |
| Subject: | Re: [RFC] Saner string to number comparisons | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104530@lists.php.net to get a copy of this message | ||
> Le 27 févr. 2019 à 09:06, Kingsquare.nl - Robin Speekenbrink <robin@kingsquare.nl> a
> écrit :
>
> As of the 0 == "" bit: I do think that an empty string is widespread
> regarded as falsey-string... Thus 0 == "" sould IMHO return true...
>
0 == "" evaluating to true has been a footgun for me in the past; something like that:
```php
$state = $_GET['state'] ?? null;
// ...
switch ($state) {
case 0: // when $state === "", this branch is incorrectly chosen
// ...
}
```
where the
state parameter comes from <select name="state"> and is
supposed to provide an optional filter criterion for some list.
The fact that both values are falsy doesn’t mean that they should be equal (hopefully,
array() == 0 evaluates to false).
—Claude