Skip to content

PHP8 "static" return type #107

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Author

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.


/**
* Return an instance with the specified header appended with the given value.
Expand All @@ -147,7 +147,7 @@ public function withHeader(string $name, $value): static;
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader(string $name, $value): static;
public function withAddedHeader(string $name, array|string $value): static;

/**
* Return an instance without the specified header.
Expand Down
8 changes: 4 additions & 4 deletions src/ServerRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function withUploadedFiles(array $uploadedFiles): static;
* @return null|array|object The deserialized body parameters, if any.
* These will typically be an array or object.
*/
public function getParsedBody();
public function getParsedBody(): null|array|object;

/**
* Return an instance with the specified body parameters.
Expand Down Expand Up @@ -194,7 +194,7 @@ public function getParsedBody();
* @throws \InvalidArgumentException if an unsupported argument type is
* provided.
*/
public function withParsedBody($data): static;
public function withParsedBody(null|array|object $data): static;

/**
* Retrieve attributes derived from the request.
Expand Down Expand Up @@ -224,7 +224,7 @@ public function getAttributes(): array;
* @param mixed $default Default value to return if the attribute does not exist.
* @return mixed
*/
public function getAttribute(string $name, $default = null);
public function getAttribute(string $name, mixed $default = null): mixed;

/**
* Return an instance with the specified derived request attribute.
Expand All @@ -241,7 +241,7 @@ public function getAttribute(string $name, $default = null);
* @param mixed $value The value of the attribute.
* @return static
*/
public function withAttribute(string $name, $value): static;
public function withAttribute(string $name, mixed $value): static;

/**
* Return an instance that removes the specified derived request attribute.
Expand Down
4 changes: 2 additions & 2 deletions src/StreamInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function close(): void;
*
* @return resource|null Underlying PHP stream, if any
*/
public function detach();
public function detach(): mixed;

/**
* Get the size of the stream if known.
Expand Down Expand Up @@ -154,5 +154,5 @@ public function getContents(): string;
* provided. Returns a specific key value if a key is provided and the
* value is found, or null if the key is not found.
*/
public function getMetadata(?string $key = null);
public function getMetadata(?string $key = null): mixed;
}