Skip to content

Commit 2b845a6

Browse files
committed
This patch updates PSR-7 to always use `@return static` instead of `@return self` within method annotations, as done in php-fig/http-message#50. Per the discussion on that issue, `static` is interpreted by phpDoc and most IDEs in such a way that it always resolves to the class against which it was invoked, and not the defining class, unlike `self`, which always resolves to the class in which it was originally defined. Additionally, `static` has the *connotation* that a new instance, not the same instance, will be returned — which is the intention as outlined already in each method providing such a return value.
1 parent f8a76eb commit 2b845a6

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

accepted/PSR-7-http-message.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ interface MessageInterface
631631
* new protocol version.
632632
*
633633
* @param string $version HTTP protocol version
634-
* @return self
634+
* @return static
635635
*/
636636
public function withProtocolVersion($version);
637637

@@ -721,7 +721,7 @@ interface MessageInterface
721721
*
722722
* @param string $name Case-insensitive header field name.
723723
* @param string|string[] $value Header value(s).
724-
* @return self
724+
* @return static
725725
* @throws \InvalidArgumentException for invalid header names or values.
726726
*/
727727
public function withHeader($name, $value);
@@ -739,7 +739,7 @@ interface MessageInterface
739739
*
740740
* @param string $name Case-insensitive header field name to add.
741741
* @param string|string[] $value Header value(s).
742-
* @return self
742+
* @return static
743743
* @throws \InvalidArgumentException for invalid header names.
744744
* @throws \InvalidArgumentException for invalid header values.
745745
*/
@@ -755,7 +755,7 @@ interface MessageInterface
755755
* the named header.
756756
*
757757
* @param string $name Case-insensitive header field name to remove.
758-
* @return self
758+
* @return static
759759
*/
760760
public function withoutHeader($name);
761761

@@ -776,7 +776,7 @@ interface MessageInterface
776776
* new body stream.
777777
*
778778
* @param StreamInterface $body Body.
779-
* @return self
779+
* @return static
780780
* @throws \InvalidArgumentException When the body is not valid.
781781
*/
782782
public function withBody(StreamInterface $body);
@@ -843,7 +843,7 @@ interface RequestInterface extends MessageInterface
843843
* @see http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
844844
* request-target forms allowed in request messages)
845845
* @param mixed $requestTarget
846-
* @return self
846+
* @return static
847847
*/
848848
public function withRequestTarget($requestTarget);
849849

@@ -866,7 +866,7 @@ interface RequestInterface extends MessageInterface
866866
* changed request method.
867867
*
868868
* @param string $method Case-sensitive method.
869-
* @return self
869+
* @return static
870870
* @throws \InvalidArgumentException for invalid HTTP methods.
871871
*/
872872
public function withMethod($method);
@@ -910,7 +910,7 @@ interface RequestInterface extends MessageInterface
910910
* @see http://tools.ietf.org/html/rfc3986#section-4.3
911911
* @param UriInterface $uri New request URI to use.
912912
* @param bool $preserveHost Preserve the original state of the Host header.
913-
* @return self
913+
* @return static
914914
*/
915915
public function withUri(UriInterface $uri, $preserveHost = false);
916916
}
@@ -1000,7 +1000,7 @@ interface ServerRequestInterface extends RequestInterface
10001000
* updated cookie values.
10011001
*
10021002
* @param array $cookies Array of key/value pairs representing cookies.
1003-
* @return self
1003+
* @return static
10041004
*/
10051005
public function withCookieParams(array $cookies);
10061006

@@ -1038,7 +1038,7 @@ interface ServerRequestInterface extends RequestInterface
10381038
*
10391039
* @param array $query Array of query string arguments, typically from
10401040
* $_GET.
1041-
* @return self
1041+
* @return static
10421042
*/
10431043
public function withQueryParams(array $query);
10441044

@@ -1064,7 +1064,7 @@ interface ServerRequestInterface extends RequestInterface
10641064
* updated body parameters.
10651065
*
10661066
* @param array $uploadedFiles An array tree of UploadedFileInterface instances.
1067-
* @return self
1067+
* @return static
10681068
* @throws \InvalidArgumentException if an invalid structure is provided.
10691069
*/
10701070
public function withUploadedFiles(array $uploadedFiles);
@@ -1110,7 +1110,7 @@ interface ServerRequestInterface extends RequestInterface
11101110
*
11111111
* @param null|array|object $data The deserialized body data. This will
11121112
* typically be in an array or object.
1113-
* @return self
1113+
* @return static
11141114
* @throws \InvalidArgumentException if an unsupported argument type is
11151115
* provided.
11161116
*/
@@ -1159,7 +1159,7 @@ interface ServerRequestInterface extends RequestInterface
11591159
* @see getAttributes()
11601160
* @param string $name The attribute name.
11611161
* @param mixed $value The value of the attribute.
1162-
* @return self
1162+
* @return static
11631163
*/
11641164
public function withAttribute($name, $value);
11651165

@@ -1175,7 +1175,7 @@ interface ServerRequestInterface extends RequestInterface
11751175
*
11761176
* @see getAttributes()
11771177
* @param string $name The attribute name.
1178-
* @return self
1178+
* @return static
11791179
*/
11801180
public function withoutAttribute($name);
11811181
}
@@ -1231,7 +1231,7 @@ interface ResponseInterface extends MessageInterface
12311231
* @param string $reasonPhrase The reason phrase to use with the
12321232
* provided status code; if none is provided, implementations MAY
12331233
* use the defaults as suggested in the HTTP specification.
1234-
* @return self
1234+
* @return static
12351235
* @throws \InvalidArgumentException For invalid status code arguments.
12361236
*/
12371237
public function withStatus($code, $reasonPhrase = '');
@@ -1605,7 +1605,7 @@ interface UriInterface
16051605
* An empty scheme is equivalent to removing the scheme.
16061606
*
16071607
* @param string $scheme The scheme to use with the new instance.
1608-
* @return self A new instance with the specified scheme.
1608+
* @return static A new instance with the specified scheme.
16091609
* @throws \InvalidArgumentException for invalid schemes.
16101610
* @throws \InvalidArgumentException for unsupported schemes.
16111611
*/
@@ -1623,7 +1623,7 @@ interface UriInterface
16231623
*
16241624
* @param string $user The user name to use for authority.
16251625
* @param null|string $password The password associated with $user.
1626-
* @return self A new instance with the specified user information.
1626+
* @return static A new instance with the specified user information.
16271627
*/
16281628
public function withUserInfo($user, $password = null);
16291629

@@ -1636,7 +1636,7 @@ interface UriInterface
16361636
* An empty host value is equivalent to removing the host.
16371637
*
16381638
* @param string $host The hostname to use with the new instance.
1639-
* @return self A new instance with the specified host.
1639+
* @return static A new instance with the specified host.
16401640
* @throws \InvalidArgumentException for invalid hostnames.
16411641
*/
16421642
public function withHost($host);
@@ -1655,7 +1655,7 @@ interface UriInterface
16551655
*
16561656
* @param null|int $port The port to use with the new instance; a null value
16571657
* removes the port information.
1658-
* @return self A new instance with the specified port.
1658+
* @return static A new instance with the specified port.
16591659
* @throws \InvalidArgumentException for invalid ports.
16601660
*/
16611661
public function withPort($port);
@@ -1679,7 +1679,7 @@ interface UriInterface
16791679
* Implementations ensure the correct encoding as outlined in getPath().
16801680
*
16811681
* @param string $path The path to use with the new instance.
1682-
* @return self A new instance with the specified path.
1682+
* @return static A new instance with the specified path.
16831683
* @throws \InvalidArgumentException for invalid paths.
16841684
*/
16851685
public function withPath($path);
@@ -1696,7 +1696,7 @@ interface UriInterface
16961696
* An empty query string value is equivalent to removing the query string.
16971697
*
16981698
* @param string $query The query string to use with the new instance.
1699-
* @return self A new instance with the specified query string.
1699+
* @return static A new instance with the specified query string.
17001700
* @throws \InvalidArgumentException for invalid query strings.
17011701
*/
17021702
public function withQuery($query);
@@ -1713,7 +1713,7 @@ interface UriInterface
17131713
* An empty fragment value is equivalent to removing the fragment.
17141714
*
17151715
* @param string $fragment The fragment to use with the new instance.
1716-
* @return self A new instance with the specified fragment.
1716+
* @return static A new instance with the specified fragment.
17171717
*/
17181718
public function withFragment($fragment);
17191719

0 commit comments

Comments
 (0)