Skip to content
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

Merged
merged 5 commits into from
Apr 4, 2023

Conversation

Stilch
Copy link
Contributor

@Stilch Stilch commented May 9, 2021

No description provided.

@Stilch Stilch changed the title Add typehints Add return typehints May 9, 2021
@McLotos
Copy link

McLotos commented Jun 20, 2021

@weierophinney @pmjones Have we an approximate date of merge? We can't wait several years for each such release =)

@McLotos
Copy link

McLotos commented Jun 20, 2021

@weierophinney @gabidj
I think this request is high time to merge with #83, then create a 2.0 version of http-message package.

@ADmad
Copy link

ADmad commented Sep 8, 2021

PHP 8.1 RC1 is out and here we are still waiting for a release for PHP 7.2+ with types 🙂.

@ADmad
Copy link

ADmad commented Dec 16, 2021

Tumbleweed

@deluxetom
Copy link

is this not maintained anymore? I would also love to see this PR merged

@simensen
Copy link

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.

https://www.php-fig.org/get-involved/

@simensen
Copy link

Any of the methods that return an instance of the same interface (the "wither" methods) should ideally have a static return type since that is now available.

@Stilch
Copy link
Contributor Author

Stilch commented Feb 16, 2022

I can add static return type, but I will have to set the minimum php version to 8.0

composer.json Outdated
@@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=7.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stilch

Looks like we are not only adding return type declarations here, but raising the PHP version requirement.

Should that be different pull requests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stilch

Not sure who suggested to use this kind of version requirement, but for reference, there is a somewhat heated discussion why using >= is not a good idea, right here.

@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stilch

Does not have any effect on interfaces.

composer.json Outdated
@@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=7.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"php": ">=7.2.0"
"php": "^7.2.0 || ^8.0.0"

@oanhnn
Copy link

oanhnn commented Apr 15, 2022

Will we continue to wait new version or will leave it (not implement interface)?
PHP 8.1 was released and PHP 7.4 Active support ended :(
https://www.php.net/supported-versions.php

@ikkez
Copy link

ikkez commented Oct 16, 2022

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.

@ADmad
Copy link

ADmad commented Oct 18, 2022

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.

@cosminsandu
Copy link

Anew news on this?

@weierophinney weierophinney mentioned this pull request Feb 21, 2023
@weierophinney
Copy link
Contributor

@ADmad

clarification if the PSR repos are maintained by the group as a whole or each one is handled by a BDFL.

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.

Copy link
Contributor

@weierophinney weierophinney left a 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 a string 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 become TypeError.
  • 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.

@shadowhand
Copy link

@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.

@weierophinney
Copy link
Contributor

@shadowhand Awesome - I'll ping you if/when the vote passes!

Copy link
Contributor

@weierophinney weierophinney left a 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"
Copy link

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.

Copy link
Contributor

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.

@vdelau vdelau merged commit 402d35b into php-fig:master Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet