[php-src] Issue #12121: DateTime::createFromFormat not works with incorrect date like 31 february

From: Date: Mon, 04 Sep 2023 14:43:01 +0000
Subject: [php-src] Issue #12121: DateTime::createFromFormat not works with incorrect date like 31 february
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245323@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12121 Author: sovetski ### Description The following code: ```php <?php var_dump( \DateTime::createFromFormat("d-m-Y", "31-02-1997") ); ``` Resulted in this output: ``` object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-03 10:25:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } ``` But I expected this output instead: ``` bool (false) or 31-02-1997 ``` When we give an incorrect date to "createFromFormat", like 31 february of any year, it gives "1997-03-03". If we give 29 february it will return "1997-03-01". As the last day of the february is 28th on 1997, all additional days are incremented to get the next month day. Is it an expected behaviour? It is very strange... ### PHP Version 8.1 ### Operating System _No response_

« previous php.bugs (#245323) next »