Re: [PHP] String conversion to integer
> I'm testing php 7.1 in my project, and I got a strange problem.
> $string = '584e82ed00819';
> echo (int)$string;
> The above code will output 9223372036854775807 (It's PHP_INT_MAX) in php
> In php 5.5, the result is: 584.
> According to the document:
> I guess php 7.1 process the string as 584e82, but 5.5 did not.
> Any differences for string conversion between 7.1 and 5.5 ?
Yes, PHP 7.1 brings the change of string casting now recognising scientific
notation. A brief mention of this is made in the migration guide:
Integer operations and conversions on numerical strings now respect scientific
notation. This also includes the (int) cast operation, and the following functions:
intval() (where the base is 10), settype(), decbin(), decoct(), and dechex().
For more reasoning on why this change has been made, you can view the Warn
about invalid strings in arithmetic RFC, specifically the "Fractional and scientific
notation strings with integer operators" subsection.