|  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: 2018-08-27 09:44 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: phper dot 0o0 at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.1.21 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: phper dot 0o0 at gmail dot com
New email:
PHP Version: OS:


 [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
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 00:01:26 2019 UTC