[php-src] Issue #11989: Inconsistent DateTime validation when creating from format

From: Date: Wed, 16 Aug 2023 15:24:34 +0000
Subject: [php-src] Issue #11989: Inconsistent DateTime validation when creating from format
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245198@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11989 Author: andrei-dascalu ### Description The following code: ```php <?php $date = DateTime::createFromFormat('Y-m-d', '22-11-11'); echo $date->format('Y-m-d'); ``` Resulted in this output: ``` 0022-11-11 ``` But I expected this output instead: ``` false ``` this is one of those inconsistencies that are a head-scratcher. If there is not enough provided information to match the format, why does DateTime simply pad with 0's instead of providing correct validation feedback? It does so if I were to use the pattern 'Y-m-d H', rather than provide 00 for the missing hours. ### PHP Version PHP 8.2.8 ### Operating System MacOS 13.5

« previous php.bugs (#245198) next »