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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to