Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for Datetime::construct with invalid value #2773

Closed
aronbeal opened this issue Sep 18, 2023 · 2 comments
Closed

Docs for Datetime::construct with invalid value #2773

aronbeal opened this issue Sep 18, 2023 · 2 comments
Assignees
Labels

Comments

@aronbeal
Copy link

aronbeal commented Sep 18, 2023

Should probably mention the fact that this throws a fatal error when passed an invalid time string.

e.g.

$value = ",3 13:42:21 -0700";
print_r(new DateTime($value));

Yields:

Fatal error: Uncaught Exception: Failed to parse time string (,3 13:42:21 -0700) at position 1 (3): Unexpected character in /home/user/scripts/code.php:4
Stack trace:
#0 /home/user/scripts/code.php(4): DateTimeImmutable->__construct(',3 13:42:21 -07...')
#1 {main}
  thrown in /home/user/scripts/code.php on line 4

Edit: Datetimeimmutable docs are correct - these should probably match those in terms of exceptions

@dreeh
Copy link
Contributor

dreeh commented Oct 9, 2023

The docs for datetime and datetimeimmutable are the same in case of exception. What's need here?

See:
https://www.php.net/manual/en/datetime.construct.php
https://www.php.net/manual/en/datetimeimmutable.construct.php

@derickr
Copy link
Contributor

derickr commented Oct 10, 2023

It does say that: https://www.php.net/manual/en/datetime.construct.php#refsect1-datetime.construct-errors — so closing this report.

@derickr derickr closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants