Bug #78383 [Csd]: Casting a DateTime to array no longer returns its properties
| From: | jeremy at derusse dot com | Date: | Thu, 08 Aug 2019 08:23:09 +0000 |
| Subject: | Bug #78383 [Csd]: Casting a DateTime to array no longer returns its properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222135@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78383&edit=1
ID: 78383
User updated by: jeremy at derusse dot com
Reported by: jeremy at derusse dot com
Summary: Casting a DateTime to array no longer returns its
properties
Status: Closed
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.4.0beta1
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Thank you @nikic
Previous Comments:
------------------------------------------------------------------------
[2019-08-08 07:56:22] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=fc17bfaacfd48b3952652792bf684ff223499678
Log: Fixed bug #78383
------------------------------------------------------------------------
[2019-08-07 20:41:48] jeremy at derusse dot com
We (symfony) implemented a generic serialization mechanism that uses array casts to extract state
from objects.
DateTime was not needing any special care, but now it would because the behavior changed between php
7.3 and 7.4, IMHO, it's a BC break.
Not https://3v4l.org/rdhKg: another change in the bevahior of
\Datetime casting.
------------------------------------------------------------------------
[2019-08-07 16:30:17] cmb@php.net
Well, then ... :)
------------------------------------------------------------------------
[2019-08-07 16:25:35] nikic@php.net
We could easily restore the previous behavior wrt array casts here -- we're already keeping
compatibility with json_encode() for example.
What's the use case?
------------------------------------------------------------------------
[2019-08-07 16:21:11] cmb@php.net
> Casting to an array is undefined, [â¦]
Not wrt. objects[1]:
| An array converts to an object with properties named by keys and
| corresponding values.
Anyhow, this is a deliberate change[2]; DateTime objects are not
supposed to have public properties.
[1] <https://www.php.net/manual/en/language.types.object.php#language.types.object.casting>
[2] <https://github.com/php/php-src/blob/be794894ef30764e54a8a52fa6c085f3c4a88b14/UPGRADING#L56-L57>
------------------------------------------------------------------------
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=78383
--
Edit this bug report at https://bugs.php.net/bug.php?id=78383&edit=1