|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-08-13 22:26 UTC] corey dot taylor dot fl at gmail dot com
Description: ------------ I don't know if this is actually a bug or intended behavior or undefined behavior. However, since it's been consistent up to 8.0.0beta1, I thought I'd report the change. https://3v4l.org/dgunY DateTime::createFromFormat() used to always return a DateTime instance if called from a class that extended DateTime and wrapped createFromFormat(). Now, it is returning the static type. In this example,that is an ExtendsDateTime instance. https://bugs.php.net/bug.php?id=60302 Looking, I see a very old bug that suggests this was supposed to be the fixed behavior, but clearly wasn't. We have some low level framework behavior keyed off the type of instance constructed, so we'd like to make sure this is the intended switch for PHP 8. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
As part of the Chronos (date/time library), we have a Date type that wraps DateTime and handles ensuring date-only values. There is logic that checks if creating an instance from a Date object or not to determine what to fix up. With this change, the unfixed instance is simply cloned. Since DateTime::createFromFormat('Y-m-d') takes the current time all this logic was added to ensure construction was valid. To be clear, this behavior seems like the correct behavior and should have been the original behavior, but since this will take some re-design to work with PHP 7 and 8, it's worth checking this won't revert back.Yeah, the current behavior here is not great. I think it should either continue returning self, or call the constructor for extended classes. A workaround would be to do something like class MyDateTime { public static function createFromFormat(...$args) { $date = parent::createFromFormat(...$args); // Do the rest of your initialization here return $date; } }