Conversation
| * @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.
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-messageto^2.0and my IDE started yelling at me because my library already requires a minimum of PHP 8.1 and i was already using the newstaticreturn type.Here, I'm proposing a v3.0 that requires a minimum of PHP 8.0:
staticmixedtypes 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
staticwas 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.