You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #50644 [VarDumper] Dumping DateTime throws error if getTimezone is false (bogdanmoza)
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[VarDumper] Dumping DateTime throws error if getTimezone is false
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR |
----
**TL;DR:**
In case you have a DateTime object that returns false when calling `getTimezone()`, an error is thrown in DateCaster.
**Description**
So I have encountered this case when I have tried to dump a mocked DateTime object. The mock will not have a timezone making the `getTimezone()` method return false. I know that this is not really a bug, as a DateTime object not having a DateTimeZone should not be happening, but it is possible in case someone extends the DateTime object and overrides the `getTimezone()` method.
The error thrown is 'The DatetimeInterface object has not been correctly initialized by its constructor'
**How to reproduce**
```
class A extends \DateTime {
public function getTimezone(): \DateTimeZone|false
{
return false;
}
}
```
Dump the A class will cause an error.
**Final notes**
Even though this a special case, I still think that you should be able to dump a mocked DateTime.
I hope the description and everything is ok as this is my first pr here.
Cheers!
Commits
-------
d6bc7a4 [VarDumper] Dumping DateTime throws error if getTimezone is false
0 commit comments