-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add return typehints #95
Conversation
@weierophinney @pmjones Have we an approximate date of merge? We can't wait several years for each such release =) |
@weierophinney @gabidj |
PHP 8.1 RC1 is out and here we are still waiting for a release for PHP 7.2+ with types 🙂. |
is this not maintained anymore? I would also love to see this PR merged |
It isn't a question of maintained or not. I'm not in a position to do anything about this package anymore. Making changes to any published PSR or its associated packages is a lengthy process. I know @weierophinney already touched on this via Twitter, so I'm including this here for context. :) Not too long ago, the mailing list was the preferred way to bring up topics related to existing or future PSRs. Looks like Discord is on the list, now, too. |
Any of the methods that return an instance of the same interface (the "wither" methods) should ideally have a |
I can add |
composer.json
Outdated
@@ -11,7 +11,7 @@ | |||
} | |||
], | |||
"require": { | |||
"php": ">=5.3.0" | |||
"php": ">=7.2.0" |
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.
Looks like we are not only adding return type declarations here, but raising the PHP version requirement.
Should that be different pull requests?
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.
src/MessageInterface.php
Outdated
@@ -1,5 +1,7 @@ | |||
<?php | |||
|
|||
declare(strict_types=1); |
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.
Does not have any effect on interfaces.
composer.json
Outdated
@@ -11,7 +11,7 @@ | |||
} | |||
], | |||
"require": { | |||
"php": ">=5.3.0" | |||
"php": ">=7.2.0" |
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.
"php": ">=7.2.0" | |
"php": "^7.2.0 || ^8.0.0" |
Will we continue to wait new version or will leave it (not implement interface)? |
It's end of 2022, php 8.2 is around the corner and still no resolution to this issue. Please abandon this project... it would be at least an answer we can work with. |
Would be nice if PHP-FIG also provides some clarification if the PSR repos are maintained by the group as a whole or each one is handled by a BDFL. |
Anew news on this? |
@ADmad —
The bylaws make clear the chain of "power" for a given spec repo: editor, sponsor, then group. I've been very slow on these, as I had quite some concerns about ecosystem impact. I've done testing on #94 at this point, and feel it's ready to go. I'm testing this one next, to determine impact for implementing libraries and existing consumers so I can write up a migration guide. When that's ready, we can start the evolution vote. I'm hoping to get that done in the next 1-4 weeks. |
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.
Questions:
- Why no
void
return types? - Why are
__toString()
occurrences not updated with astring
return type declaration?
Otherwise, this looks good.
I tested against the PSR-7 integration test suite and Diactoros. The changes:
- Updating signatures. Surprisingly, we've added typehints previously in Diactoros, so there were not many changes needed. I ran into more when I tested an app that uses mezzio-swoole, as that library imlements
StreamInterface
, and needed both parameter and return hints. - Removing obsolete tests. A huge portion of both the integration tests and the Diactoros tests are around validating that invalid input will not be accepted. Since implementations previously needed to throw
InvalidArgumentException
, these now become caught by the language and becomeTypeError
. - Fixing invalid tests. There were a few cases where now-invalid arguments were being passed to interface methods (e.g. when testing that IANA phrases were being used for known status code/reason phase combinations, Diactoros was not casting the status codes pulled from a text file to integer).
Once these changes were made, tests passed as expected.
I then tried the code in a few real-world apps, including one that uses mezzio-swoole, in order to see the effect on consumers. These worked as expected.
My main concern will be that in some cases, we allowed numeric strings for what are now typed as integer arguments, which could have some impact on consumers. That said, this change would require opting in to the new major version, and the changes can be messaged via a blog post or the release notes.
The other issue is going to be PSR-17 and its implementations, as it currently pins against v1, which prevents updating a library implementation that implements both PSR-7 and PSR-17 to a PSR-7 v2 release. We'll need to coordinate with @shadowhand when we're preparing this so that he can update the PSR-17 repo to allow usage with v2 as well.
I think if you can answer the questions listed at the start of this review (either with a reasonable comment response, or code changes), this will be ready. There's also the additional benefit that I've done work in one widely-used implementation, which means we should get adoption of the new version relatively quickly.
@weierophinney thank you for testing this out and the detailed report. I am happy to start working on updating PSR-17 (and PSR-15) for this change. |
@shadowhand Awesome - I'll ping you if/when the vote passes! |
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.
Changes look good, thanks! I'll get the vote started for these this week!
composer.json
Outdated
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0" | ||
"php": "^7.2.0 || ^8.0.0" |
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.
As with the first PR, let's go straight to 8. There are no supported 7.x versions anymore.
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.
I disagree.
Ubuntu 20.04, RHEL 7, and Debian 11 are all pinned to PHP 7.4 still, and these are all LTS editions. It makes sense to allow them to be able to update to the 1.1 release.
No description provided.