-
Couldn't load subscription status.
- Fork 8k
Implement DateTime Exceptions RFC #10366
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --TEST-- | ||
| DateInterval constructor exceptions | ||
| --INI-- | ||
| date.timezone=Europe/London | ||
| --FILE-- | ||
| <?php | ||
| function check(callable $c) | ||
| { | ||
| try { | ||
| var_dump($c()); | ||
| } catch (\DateMalformedIntervalStringException $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
| } | ||
|
|
||
| check(fn() => new DateInterval("")); | ||
| check(fn() => new DateInterval("2007-05-11T15:30:00Z/")); | ||
| ?> | ||
| --EXPECTF-- | ||
| DateMalformedIntervalStringException: Unknown or bad format () | ||
| DateMalformedIntervalStringException: Failed to parse interval (2007-05-11T15:30:00Z/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --TEST-- | ||
| Test DateInterval::createFromDateString() function : nonsense data | ||
| --FILE-- | ||
| <?php | ||
| try { | ||
| $i = DateInterval::createFromDateString("foobar"); | ||
| } catch (DateMalformedIntervalStringException $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
| ?> | ||
| --EXPECTF-- | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this can now be EXPECT instead of EXPECTF :) |
||
| DateMalformedIntervalStringException: Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| DateInterval invalid serialization data with date_string | ||
| --FILE-- | ||
| <?php | ||
| $propertySets = [ | ||
| '2023-01-16 17:01:19', | ||
| '2023-01-16-foobar$*', | ||
| ]; | ||
|
|
||
| foreach( $propertySets as $propertySet ) | ||
| { | ||
| try { | ||
| $d = DateInterval::__set_state( [ 'date_string' => $propertySet ] ); | ||
| echo "OK\n"; | ||
| } catch (\Error $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| OK | ||
derickr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Error: Unknown or bad format (2023-01-16-foobar$*) at position 10 (-) while unserializing: Unexpected character | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @derickr, looking at https://3v4l.org/iSPL9,
it doesn't seem possible for
to return false anymore.
Shouldn't the stub be updated then ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VincentLanglet Good catch, I've just filed #14600 fixing these return types.