Bug #79041 [Asn->Wfx]: PHP 7.4 changed foreach behavior for DateTime object

From: Date: Fri, 22 Jul 2022 16:20:34 +0000
Subject: Bug #79041 [Asn->Wfx]: PHP 7.4 changed foreach behavior for DateTime object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241985@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79041&edit=1

 ID:                 79041
 Updated by:         derick@php.net
 Reported by:        robert at korulczyk dot pl
 Summary:            PHP 7.4 changed foreach behavior for DateTime object
-Status:             Assigned
+Status:             Wont fix
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.4.1
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

I'm going to mark this as "won't fix". DateTime(Immutable) does not have real
properties, and the once that show up with serialize/json_encode, and (array), are there to handle
this specific case.


Previous Comments:
------------------------------------------------------------------------
[2021-02-09 12:53:23] drodriguez816 at gmail dot com

Also there is a problem with reflection.
Reflection is not returning the datetime properties. So $props array will remain empty..

$date = new DateTime();
$reflection = new ReflectionObject($date);
$props = [];

foreach ($reflection->getProperties() as $p) {
    $props[] = $p->getName();
}

var_dump($props);

------------------------------------------------------------------------
[2020-01-20 17:09:02] girgias@php.net

Not sure if this shouldn't be a feature request, assigning to Derick as he is the maintainer of
the Date extension.

------------------------------------------------------------------------
[2020-01-10 20:23:21] camporter1 at gmail dot com

Would it be possible to list this in the BC section of the 7.3 to 7.4 migration docs?

------------------------------------------------------------------------
[2020-01-01 21:28:52] robert at korulczyk dot pl

Any plans to fix this mess in PHP 8? Current behavior is really confusing, especially with BC hack
for (array) cast.

------------------------------------------------------------------------
[2019-12-30 16:15:11] nikic@php.net

Not willing to provide BC for this. DateTime doesn't have virtual properties -- it has a debug
representation (think __debugInfo()).

To account for that particular use-case it would be nice if DateTime implemented JsonSerializable
rather than doing the same via an internal side-channel. Unfortunately that is a bit problematic as
json is an optional extension.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=79041


--
Edit this bug report at https://bugs.php.net/bug.php?id=79041&edit=1


Thread (7 messages)

« previous php.bugs (#241985) next »