-
Notifications
You must be signed in to change notification settings - Fork 188
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
Adds parameter typehints #94
Conversation
Quick note, they are called type and return type declarations, see https://www.php.net/manual/en/language.types.declarations.php. |
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 only have one change to make (PHP constraint), and can make that myself and push to your branch if you like.
I've tested this against the PSR-7 integration test suite, and also tried it in a few applications to see the impact; all worked as expected, indicating it's backwards compatible with the previous versions. As such, I think this one is ready, pending the evolution approval.
Will turn to reviewing #95 next. I expect that's going to be the harder one.
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.
Please do not use >=
(or, worse, *
) for constraints; there's no way of knowing if a later major will result in BC breaks.
"php": ">=7.2.0" | |
"php": "^7.2 || ^8.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.
Is there consensus on this topic (no intention to start a discussion about the pros and cons)? It looks like most other PSRs and also the existing v1 use >=
, so we may want to keep using this here as well for consistency reasons, no?
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.
We don't have any bylaws for it, and many of these pre-dated some of our current understanding of what is reasonable to expect for backwards compatibility guarantees from PHP.
Laminas, for instance, uses ~X.Y.0
constraints, because we've found that there are subtle BC breaks often between minor versions.
Considering we do not know what keywords will be reserved for a new major, nor what subtle changes to the object model might cause breakage, I feel we should be cautious in what we say we support. We can always create a new minor to add support for a new PHP major when the time comes, but removing support for the new major if we discover breakage would technically be a BC break.
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 think we both agree this would not be the right place to have this discussion and I think we're both very well aware of the pros and cons of both approaches. Neither approach is perfect, it's a tradeoff. Hence my question if there is (or should be) a bylaw that goes into more detail.
In my opinion, it really comes down to expectations and how we (can) look into our crystal ball. I would argue I have no reason to believe a set of interfaces like PSR-7 would be incompatible with PHP 9 and beyond – or at least I have equal certainty it will be compatible with PHP 8.4 or beyond. Both assumptions are guess work at this point imho, so I could even understand the move to pin to the minor version like done for Laminas and others.
I guess I could rephrase my thoughts: Do we have more reason to believe PHP 9 would break PSR-7 v2 than we have reason to believe that a future PSR-7 v2.x would be ready in time PHP 9 is foreseeable? I would hate to hinder adoption of new PHP versions in the future.
@@ -129,7 +131,7 @@ public function getHeaderLine($name); | |||
* @return static | |||
* @throws \InvalidArgumentException for invalid header names or values. | |||
*/ | |||
public function withHeader($name, $value); | |||
public function withHeader(string $name, $value); |
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.
This one is interesting; when we bump to PHP 8, we could make $value
into string|array
, though an array type would still require validation.
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.
So should we go ahead and do that before the vote? It seems wise to do so if that's what the spec already calls for.
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.
No - we can do it for a later minor version that bumps the minimum version to 8. For this one, we should keep PHP 7 support (per my other comments).
@@ -224,7 +226,7 @@ public function getAttributes(); | |||
* @param mixed $default Default value to return if the attribute does not exist. | |||
* @return mixed | |||
*/ | |||
public function getAttribute($name, $default = null); | |||
public function getAttribute(string $name, $default = null); |
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.
When we move to PHP 8, we could add mixed
as the type for $default
.
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.
RequestInterface::withRequestTarget()
should add a string
typehint for the $requestTarget
argument, as those are all that are allowed based on RFC-7230.
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 good! I'll open the vote for these updates this week!
@@ -55,10 +57,10 @@ public function getRequestTarget(); | |||
* | |||
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various | |||
* request-target forms allowed in request messages) | |||
* @param mixed $requestTarget | |||
* @param string $requestTarget |
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.
Was this an error before?
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.
Yes - if you look at the linked RFC 7230 section, you'll see it can only be a string.
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.
refs #78
@@ -11,7 +11,7 @@ | |||
} | |||
], | |||
"require": { | |||
"php": ">=5.3.0" | |||
"php": "^7.2 || ^8.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.
I'd vote for going straight to 8.x and be done with it. Use the union types.
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 noted on #95, I think it makes sense to allow v7 here, due to the large install base of RHEL 7, Ubuntu 20.04, and Debian 11, all of which pin to PHP 7.4. We will have PHP 7 users for some years, even if it's not technically in support, and there's no reason to restrict its usage artificially.
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.
Aren't there some places where you wanted to use mixed
, though? Why punt on that unnecessarily?
Most of the other PSR updates have targeted 8.x (they used mixed
or union types), and in practice... how many people use the pinned old versions of PHP on distros rather than PPCs? I admittedly only know from one corporate environment (my own), but we're ignoring that. I don't get the sense that distro versions matters anywhere near as much as it used to.
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.
Aren't there some places where you wanted to use
mixed
, though? Why punt on that unnecessarily?
We can do a 2.1 release that restricts to 8.0 and up and adds mixed
.
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 don't get the sense that distro versions matters anywhere near as much as it used to.
They absolutely do.
We (Zend) just released our annual PHP Landscape Report. It is very representative of the broader PHP community, has a representative mix of developers to decision makers, and covers a broad spectrum of company sizes.
This year, as in all years past that I can remember, 60% of respondents are currently using EOL versions of PHP.
There's no reason to artificially restrict what features or security fixes they can get in the PHP libraries they consume because they are on an EOL version of PHP. They may be getting security patches for the runtime already (e.g., via an operating system, or via a commercial LTS provider), so limiting what they can use makes it harder to keep the libraries they use updated.
No description provided.