-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Date Period Iteration #227
Conversation
Sorry i didn't see your PR until now since there was no issue attached ot it. I ll look into it. |
Right, so I don't even know if this is fixable for PHP 7.x as it defines a custom internal iterator see:
The issue is those are not publicly available methods because it doesn't implement the Iterator or IteratorAggregate interface, so if you need to make a custom object to fix this issue it won't be usable out of the box even if you extend So for PHP 7.x it's or Wont Fix or you will need to implement a custom iterator on the object. |
The more I look at it, the more I think this is a bug in the DatePeriod implementation. The How could I believe the instances returned by We should probably file a bug in PHP regarding this behaviour. |
Yes, I think the only short term solution is to add methods to get a regular DatetimeImmutable from the safe version and vice-versa, and always to use the regular version with DatePeriod. The real question now is: how to enforce this behavior? Could we edit the phpstan rules for example? See #229 |
If I understand correctly, you mean:
The question is: can we override the "internal iterator" implemented by
@Kharhamel you can still give it a shot, but there are chances that it won't work. |
No, not at all. I mean that we should use the regular DatePeriod and always give them regular DatetimeImmutable, which means we means methods to easily switch between regular and safe versions. |
The workarounds and the bug test were released in v1.2.0. I will close this PR and open an issue. |
This test-case is a bit indirect, but it looks like doing iteration with a
\DatePeriod
object messes up the internal state (so calling any methods that depend on it will fail,format
in this example).I don't have a fix... suggestions?