Title: ServerRequest::withAttribute
Published: May 20, 2026

---

# ServerRequest::withAttribute( $attribute,  $value ): static

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-serverrequest/withattribute/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-serverrequest/withattribute/?output_format=md#source)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-serverrequest/withattribute/?output_format=md#wp--skip-link--target)

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-serverrequest/withattribute/?output_format=md#return)󠁿

 static

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclientdependencies-nyholm-psr7-serverrequest/withattribute/?output_format=md#source)󠁿

    ```php
    public function withAttribute($attribute, $value): ServerRequestInterface
    {
        if (!\is_string($attribute)) {
            throw new \InvalidArgumentException('Attribute name must be a string');
        }
        $new = clone $this;
        $new->attributes[$attribute] = $value;
        return $new;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/third-party/nyholm/psr7/serverrequest.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/ServerRequest.php#L142)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/ServerRequest.php#L142-L150)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclientdependencies-nyholm-psr7-serverrequest%2Fwithattribute%2F)
before being able to contribute a note or feedback.