Re: [RFC] Warning for implicit float to int conversions
| From: | Rowan Tommins | Date: | Sat, 06 Feb 2021 19:32:04 +0000 |
| Subject: | Re: [RFC] Warning for implicit float to int conversions | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113103@lists.php.net to get a copy of this message | ||
On 06/02/2021 14:47, Christian Schneider wrote:
I'm sure there is a lot of code which takes user input and uses (int) casts to ensure they are dealing with integers. There is also intval() as an alternative but my guess would be that real world code uses 50% (int) and 50% intval() to do this.My thoughts exactly. Code along these lines is common and, in my opinion, perfectly reasonable: $id = (int)$_GET['id']; if ( $id !== 0 ) {
// throw an exception, return false, look up a default, etc, as the application's design requires} // proceed knowing that $id is a non-zero integer I would however welcome a new function or syntax that either performs a "strict cast" (producing an error if the cast is lossy in any way) or checks in advance if a cast *would be* lossy. Regards, -- Rowan Tommins [IMSoP]