-
Notifications
You must be signed in to change notification settings - Fork 135
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
Change the signatures to use \DateTimeInterface instead \DateTime #84
Comments
Well, changing to |
Also, this makes the library incompatible with PHP < 5.5.0. |
OK, I agree, I haven't seen this when I looked at the docs for the interface. What about the date constructor trait? This would allow me to use it with Chronos. |
Implementing |
@simshaun you can't implement DatetimeInterface.
But about the php version, check http://php.net/eol.php, 5.4 reached it's end of life 5 month ago. |
I should have worded that differently. I meant "integrate by type hinting". While userland classes can't implement the interface, it would still allow libraries that extend \DateTime or \DateTimeImmutable to be passed in to Recurr. Also, I know 5.4 is end-of-life, but a large number of people are still |
Accidentally hit close button on phone... Anyway, a large number of people are still on 5.4. I still don't think this an important enough feature to warrant raising the requirement. |
This makes it pretty difficult to use this library with You can see from the below link that the vast majority of projects are now 5.5 or greater, and official support for php 5.4 ended about a year ago (http://php.net/supported-versions.php). Even 5.5 is near EOL. https://seld.be/notes/php-versions-stats-2016-1-edition Also, I'm not sure using a trait is such a great idea. I think that #85 is a good path, but it may be even better to just switch over to |
Version requirement will be raised and this will be implemented for 2.0. |
Didn't make it into 2.0, did it? Would a PR be helpful at all? |
A PR would be welcome, thanks. |
* Typehint \DateTimeInterface instead of \DateTime. Resolves #84 * Bump required minimum PHP version to 5.5
Thanks to @foaly-nr1, this has been done. Due to the method signature changes, I've released this in v3.0. https://github.com/simshaun/recurr/releases/tag/v3.0 |
I'd like again to throw in that DateTimeImmutable thing because at the moment the annotations are to return DateTimeInterface which is unfortunately not very helpful, I'd say it "improved to the worse": now you don't know what exactly to expect. |
@afoeder whenever you use interfaces you won't know what implementation to expect but there is rarely a need to know. The use of interfaces for type hints has widely been accepted as best practice. |
@foaly-nr1 still not sure whether I agree on return types being interfaces in concrete classes. In a concrete class one should know better what to return than an interface.
|
@afoeder a good part of this library returns whatever concrete class you pass into it. So we'd end up with some return types being concrete and some being interfaces. That seems worse to me. |
that's kind of exactly why I think annotating interfaces is/was made too easy. There are mixed return types and annotating interfaces is just "slightly" better. And "some being concrete and some being interfaces" would still be better than all being interfaces, at least adopters know what to trust. |
You can still use a |
not when my further code relies on (whatever DateTime or DateTimeImmutable) |
I can't think of an example where your code relies on the concrete class apart from type hints. Can you give me an example? |
hmm I think I didn't get you… I meant "…when my further code relies on concrete DateTime or DateTimeImmutable"; doesn't matter which one, just: when my code does not rely on the interface type hint but the concrete type hint. |
How can code rely on |
[sorry, forgot to reply]: type hints: i.e. when prescribing DateTimeImmutable via type hints; that's what I mean: all my code expects DateTimeImmutable except when otherwise required; I don't have such a case though and I honestly also can't think of one. |
The current implementation makes it impossible to use any custom implementation of a date time object.
Also it would be good to be able to tell the lib which object it should construct.
There are a few places where this is hard coded. I've seen the DateTime object is used a lot in at least three classes. So changing this is pretty difficult without overloading lots of methods.
A possible solution to the second problem could be a trait:
And replace the
new \DateTime()
calls with$this->getDateTime()
.The text was updated successfully, but these errors were encountered: