Skip to content

InvalidArgumentException: Attribute name must be a string in file /var/task/vendor/nyholm/psr7/src/ServerRequest.php #15

Description

@DanRVP

When parsing path parameters like /{param} an exception is thrown. Stack trace:

InvalidArgumentException: Attribute name must be a string in file /var/task/vendor/nyholm/psr7/src/ServerRequest.php on line 174
Stack trace:
  1. InvalidArgumentException->() /var/task/vendor/nyholm/psr7/src/ServerRequest.php:174
  2. Nyholm\Psr7\ServerRequest->withAttribute() /var/task/vendor/bref/dev-server/src/Router.php:119
  3. Bref\DevServer\Router->addPathParameters() /var/task/vendor/bref/dev-server/src/Router.php:76
  4. Bref\DevServer\Router->match() /var/task/vendor/bref/dev-server/src/Handler.php:45
  5. Bref\DevServer\Handler->handleRequest() /var/task/vendor/bref/dev-server/src/server-handler.php:11

This is caused by preg_match returning numeric keys in Router::addPathParameters() line 119:
Image

Input from preg_match() looks like:

array(2) {
  [0]=>
  string(11) "param_value"
  ["param"]=>
  string(11) "param_value"
}

I ran this setup in Docker with the image bref/php-83-dev:3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions