|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76790 When inheriting DateTimeImmutable, the return value type is different depending
Submitted: 2018-08-24 05:37 UTC Modified: 2020-04-11 13:04 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: phper dot 0o0 at gmail dot com Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 7.1.21 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 - 21 = ?
Subscribe to this entry?

 [2018-08-24 05:37 UTC] phper dot 0o0 at gmail dot com
The following code will return `DateTimeImmutable` when using the `createFromFormat` method.

However, the following code will return `ChildDateTimeImmutable` when `setDate` is executed.

Test script:
class ChildDateTimeImmutable extends DateTimeImmutable

$child = new ChildDateTimeImmutable('2018-08-01');
assert($child->createFromFormat('Y-m-d', '2018-01-01') instanceof ChildDateTimeImmutable);
assert($child->setDate(2018, 1, 1) instanceof ChildDateTimeImmutable);

Expected result:
I expectation is to return `ChildDateTimeImmutable` when using` createFromFormat`.

Actual result:
Warning: assert(): assert($child->createFromFormat('Y-m-d', '2018-01-01') instanceof ChildDateTimeImmutable) failed in /private/tmp/20180824140235.php on line 7

Call Stack:
    0.0009     361408   1. {main}() /private/tmp/20180824140235.php:0
    0.0049     362504   2. assert() /private/tmp/20180824140235.php:7


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-27 09:44 UTC]
-Package: *General Issues +Package: Date/time related
 [2020-01-20 17:37 UTC]
-Assigned To: +Assigned To: derick
 [2020-01-20 17:37 UTC]
Is this the expected behaviour Derick?
 [2020-04-11 13:04 UTC]
-Status: Assigned +Status: Not a bug
 [2020-04-11 13:04 UTC]
This behavior is to be expected, because ::createFromFormat() is a
*static* method, and as such is not even aware of the object it is
called upon.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 09:01:23 2020 UTC