Bug #76790 [Asn->Nab]: When inheriting DateTimeImmutable, the return value type is different depending

From: Date: Sat, 11 Apr 2020 13:04:06 +0000
Subject: Bug #76790 [Asn->Nab]: When inheriting DateTimeImmutable, the return value type is different depending
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226526@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: cmb@php.net Reported by: phper dot 0o0 at gmail dot com Summary: When inheriting DateTimeImmutable, the return value type is different depending -Status: Assigned +Status: Not a bug Type: Bug Package: Date/time related Operating System: All PHP Version: 7.1.21 Assigned To: derick Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-01-20 17:37:02] girgias@php.net Is this the expected behaviour Derick? ------------------------------------------------------------------------ [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 (#226526) next »