Bug->Doc #77701 [Ver]: \DateTime::createFromFormat does not set default parts

[email protected] Fri, 20 May 2022 14:52:55 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=77701&edit=1

 ID:                 77701
 Updated by:         [email protected]
 Reported by:        zerkms at zerkms dot ru
 Summary:            \DateTime::createFromFormat does not set default
                     parts
 Status:             Verified
-Type:               Bug
+Type:               Documentation Problem
 Package:            Date/time related
 Operating System:   linux
 PHP Version:        7.3.2
 Block user comment: N
 Private report:     N

 New Comment:

I am marking this as Documentation Problems, as this behaviour is now long standing, and not only applicable for the 'u' character. The same behaviour occurs for other time related characters too.

We can break this behaviour again, but I am not really willing to do so.


Previous Comments:
------------------------------------------------------------------------
[2019-03-06 04:23:34] [email protected]

https://3v4l.org/ZpIWq

------------------------------------------------------------------------
[2019-03-06 04:11:50] zerkms at zerkms dot ru

Description:
------------
As documentation says (http://php.net/manual/en/datetime.createfromformat.php):

If format does not contain the character ! then portions of the generated time which are not specified in format will be set to the current system time.

While in php >= 7.3.0 it's not the case anymore. Date fractions are filled, but time are zeroed.

➜ docker run -v $(pwd):/app --rm php:7.2-cli php /app/dt.php
int(1551845370)
string(29) "2019-03-06T04:09:30.000+00:00"

➜ docker run -v $(pwd):/app --rm php:7.3-cli php /app/dt.php
int(1551845374)
string(29) "2019-03-06T00:00:00.000+00:00"

Test script:
---------------
<?php

$now = \DateTime::createFromFormat('u', 0);

var_dump(time(), $now->format(\DateTime::RFC3339_EXTENDED));



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77701&edit=1