Bug #76790 [Opn]: When inheriting DateTimeImmutable, the return value type is different depending

From: Date: Mon, 20 Jan 2020 17:37:02 +0000
Subject: Bug #76790 [Opn]: When inheriting DateTimeImmutable, the return value type is different depending
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225012@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76790&edit=1 ID: 76790 Updated by: girgias@php.net Reported by: phper dot 0o0 at gmail dot com Summary: When inheriting DateTimeImmutable, the return value type is different depending Status: Open Type: Bug Package: Date/time related Operating System: All PHP Version: 7.1.21 -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: Is this the expected behaviour Derick? Previous Comments: ------------------------------------------------------------------------ [2018-08-24 05:37:07] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76790&edit=1

« previous php.bugs (#225012) next »