Re: RFC: Strict comparisons
| From: | Rowan Collins | Date: | Tue, 20 Sep 2016 12:58:20 +0000 |
| Subject: | Re: RFC: Strict comparisons | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96035@lists.php.net to get a copy of this message | ||
On 19 September 2016 14:04:48 BST, Vesa Kaihlavirta <vpkaihla@gmail.com> wrote:
>My idea is to add a strict_comparisons declaration that you can add at
>the
>beginning of a file in the same way as strict_types. The effect would
>be
>that all normal comparisons would make a type check before doing the
>actual
>comparison, and throw a TypeError exception if the types don't match.
Hm, that's definitely an interesting idea. It occurs to me that there are a few things to
"being strict" beyond type equality.
For instance === will also (I think) stop PHP juggling *both sides* of a comparison, e.g. two
numeric strings will sometimes be compared numerically rather than bytewise.
Using if statements with non-booleans also feels closely related - should the setting (or another
new flag?) throw an error on if($foo) being implicitly processed as if(empty($foo))?
Regards,
--
Rowan Collins
[IMSoP]