-
Notifications
You must be signed in to change notification settings - Fork 68
PHP 8.1 implictly converting from float to int loses precision in StringUtil.php #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
PETOSS-564 |
Thanks for raising an issue, a ticket has been created to track your request |
I'm getting this when I am working with payment dates. example: Deprecated: Implicit conversion from float 1507667758.76 to int loses precision in [...]/vendor/xeroapi/xero-php-oauth2/lib/StringUtil.php on line 80 but not on this I'm guessing it's because the "date" is rounded up, and the updated_date_utc isn't. date: /Date(1507593600000+0000)/ |
Come on Xero - this is pretty basic deprecation from a now mature version of PHP. public static function convertStringToDateTime($data)
{
if (self::checkThisDate($data)) {
return new \DateTime($data);
} else {
// convert Microsfot .NET JSON Date format into native PHP DateTime()
$seconds = null;
if (preg_match('/([\d]{11})/', $data, $date)) {
$seconds = (int)($date[1]/1000); // Explicitly cast to int
}
if (preg_match('/([\d]{12})/', $data, $date)) {
$seconds = (int)($date[1]/1000); // Explicitly cast to int
}
if (preg_match('/([\d]{13})/', $data, $date)) {
$seconds = (int)($date[1]/1000); // Explicitly cast to int
}
if ($seconds !== null) {
$datetime = new \DateTime();
$datetime->setTimestamp($seconds);
$result = $datetime->format('Y-m-d H:i:s');
return new \DateTime($result);
}
// Return a default value or throw an exception if no valid timestamp found
throw new \InvalidArgumentException("Unable to parse date/time value: $data");
}
} |
SDK you're using (please complete the following information):
Describe the bug
In PHP 8.1, it issues a warning when implicitly converting the $seconds variable to int in line 80 in StringUtil.php.
To Reproduce
Execute any code that enters the convertStringToDateTime function and enters the else statement
Additional Context
This can be fixed by changing line 80 in String Util.php from:
$datetime->setTimestamp($seconds);
To:
$datetime->setTimestamp((int)$seconds);
The text was updated successfully, but these errors were encountered: