php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81500 Interval serialization regression since 7.3.14 / 7.4.2
Submitted: 2021-10-04 11:28 UTC Modified: 2021-10-15 13:56 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kylekatarnls at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 8.0.11 OS:
Private report: No CVE-ID: None
 [2021-10-04 11:28 UTC] kylekatarnls at gmail dot com
Description:
------------
When DateInterval f property = -0.000001, it's properly restored as float(-1.0E-6) after unserialize(serialize()) until PHP 7.3.13 / 7.4.1 but since 7.3.14 / 7.4.2 and all >= 8, it becomes int(-1)

See https://3v4l.org/t5N4d

Test script:
---------------
$interval = new DateInterval('PT1S');
$interval->f = -0.000001;

var_dump($interval->s, $interval->f);

echo "\n";
$interval = unserialize(serialize($interval));

var_dump($interval->s, $interval->f);

Expected result:
----------------
int(1)
float(-1.0E-6)

int(1)
float(-1.0E-6)

Actual result:
--------------
int(1)
float(-1.0E-6)

int(1)
int(-1)

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-06 08:24 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-10-06 08:24 UTC] cmb@php.net
That's caused by the fix for bug #79015.
 [2021-10-12 09:36 UTC] cmb@php.net
Well, actually the *un*serialization is correct, because negative
values of DateInterval::$f are not supposed to be supported.
 [2021-10-12 09:37 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #81500: Interval serialization regression since 7.3.14 / 7.4.2
On GitHub:  https://github.com/php/php-src/pull/7572
Patch:      https://github.com/php/php-src/pull/7572.patch
 [2021-10-13 10:47 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #81500: Interval serialization regression since 7.3.14 / 7.4.2
On GitHub:  https://github.com/php/php-src/pull/7575
Patch:      https://github.com/php/php-src/pull/7575.patch
 [2021-10-15 11:49 UTC] alec at alec dot pl
My two cents. I see two issues here:
1. The type is int, but should be float.
2. If it's supposed to not accept negative numbers (which I agree), then I'd expect it to be converted to 0 not -1.

Former is an obvious bug, but for the latter I'm not sure. What's a usual PHP behavior is such cases.
 [2021-10-15 13:56 UTC] cmb@php.net
> The type is int, but should be float.

This cannot be fixed for BC reasons[1].

> If it's supposed to not accept negative numbers (which I agree),
> then I'd expect it to be converted to 0 not -1.

Generally, negative values are supported just fine, so we cannot
change this for BC reasons either.

The intention was to return FALSE when reading the property, but
that won't happen due to the mentioned issue[1].

[1] <https://github.com/php/php-src/pull/7575#issuecomment-943265422>
 [2021-10-15 17:14 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/866adb122a4a1d7062771fb7d239029b23c61d7a
Log: Fix #81500: Interval serialization regression since 7.3.14 / 7.4.2
 [2021-10-15 17:14 UTC] git@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC