Doc #76588 [Com]: var_export change variable state
| From: | fridgekacooler at gmail dot com | Date: | Tue, 17 Aug 2021 12:39:48 +0000 |
| Subject: | Doc #76588 [Com]: var_export change variable state | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19077@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76588&edit=1
ID: 76588
Comment by: fridgekacooler at gmail dot com
Reported by: sukei13 at gmail dot com
Summary: var_export change variable state
Status: Verified
Type: Documentation Problem
Package: Date/time related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Me too have experience this bug
https://kacoolerfridge.com/refrigerator-supplier/
Previous Comments:
------------------------------------------------------------------------
[2021-04-07 16:40:58] cmb@php.net
See also bug #74054, which is a request to change that.
------------------------------------------------------------------------
[2020-06-14 22:26:27] cmb@php.net
Comparing DateInterval instances cannot be well defined (consider
e.g. P1M and P30D); as of PHP 7.4.0, comparisons raise a warning
and evaluate to FALSE. Prior to that version, their behavior was,
let's say, undefined.
While that change is noted in the migration guide[1], it is not
yet documented in the manual proper (not sure, *where* this should
be documented).
[1] <https://www.php.net/manual/en/migration74.incompatible.php#migration74.incompatible.datetime>
------------------------------------------------------------------------
[2018-07-06 13:37:46] sukei13 at gmail dot com
Doing further tests, it appears that the print_r function has the same behavior as var_export.
------------------------------------------------------------------------
[2018-07-06 13:30:04] sukei13 at gmail dot com
Description:
------------
The result of a comparison (soft: ==) between two date intervals change when the variable has been
exported (var_export) earlier. The var_export function affect the internal state of the DateInterval
object in some way. The following test script show this weird behavior. Note that this test has been
made on other objects too (such as DateTime or DateTimeImmutable) but DateInterval seems to be the
only object involved in this issue.
Test script:
---------------
<?php
$a = new DateInterval('P2Y4DT6H8M');
$b = new DateInterval('P2Y4DT6H8M');
var_dump($a == $b); // true
var_export($b, true);
var_dump($a == $b); // false
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(true)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76588&edit=1