[9.x] Add methods to get request data as integer or float#44239
Conversation
|
Something that came up in my live stream and separately on Twitter is the integer conversion of Someone is welcome to support this edge case, but I felt it better to align with PHP. There's an argument for PHP to update the behavior of |
|
@jasonmccreary why not use casting instead of Yes, I know, it may be considered a micro-optimization, but easy enough to change it. |
|
Clarity and consistency with other parts of the framework. However, there are instances of both types of casting. So feel free to open a follow-up PR if it's truly still faster (that article is 8 years old) and all the test cases pass. @ejunker, I actually did a quick benchmark on PHP 8.1 and they are exactly the same. If anything, Script $time_start = microtime(true);
for ($i = 0; $i < 100000; ++$i) {
intval("$i");
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "ran in: $time\n"; |
This adds methods to conveniently retrieve and cast request data as an
intandfloat. Aboolcast already existed. So why not have other common scalar types.Before
After