php.net |  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
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
Have you experienced this issue?
Rate the importance of this bug to you:

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


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

Test script:
---------------
<?php
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-27 09:44 UTC] cmb@php.net
-Package: *General Issues +Package: Date/time related
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Dec 11 23:01:25 2018 UTC