-
Notifications
You must be signed in to change notification settings - Fork 186
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
PHP8 "static" return type #107
base: master
Are you sure you want to change the base?
Conversation
@@ -129,7 +129,7 @@ public function getHeaderLine(string $name): string; | |||
* @return static | |||
* @throws \InvalidArgumentException for invalid header names or values. | |||
*/ | |||
public function withHeader(string $name, $value): static; | |||
public function withHeader(string $name, array|string $value): static; |
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.
Thinking about it, this should rather accept mixed
to include scalar types, as some implementations are already implemented this way, ignoring the defined type in the docblock.
Declaring a return type of static does not throw any sort of mismatch error in any version of php 8.x Sounds like Phan was raising a false positive // no error... something something covariance https://www.php.net/manual/en/language.oop5.variance.php
// returning static satisfies the contract with interface
public function withProtocolVersion(string $version): static
{
if ($version === $this->protocolVersion) {
return $this;
}
$clone = clone $this;
$clone->protocolVersion = $version;
return $clone;
} Unrelated: what was the point of the 1.1 release? |
It might have been and is perhaps fixed in the meantime. However, the issue with incompatible return types in child classes still stands, which is what |
Hi! I just upgraded
psr/http-message
to^2.0
and my IDE started yelling at me because my library already requires a minimum of PHP 8.1 and i was already using the newstatic
return type.Here, I'm proposing a v3.0 that requires a minimum of PHP 8.0:
static
mixed
types have been addedarray|string
) have been addedThis update would make the PSR-7 interfaces finally fully typed and I am asking (no I am begging) for a swift review and release ideally before PHP 9 arrives. Thanks!
Edit: I am very well aware that this would break compatibility with v2.0. However, the issue is not the BC break of this PR but the fact that v2.0 was released 3 months ago (2023-04-17) and PHP 8.0 was released almost 3 years ago (2020-11-06), so missing
static
was not just an oversight, but a collective failure.So how to proceed? The easiest "fix" for damage control would be to just remove the <interface> return types from the current v2.0 and re-tag it, so that future installs just ignore the return type while maintaining compatibility in both directions. As an alternative, limit v2,0 to PHP
^7.2
.