Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

How do I access these values in the $request

I am inside Handler.php function render($request, Exception $exception) and I did dd($request) and got this printed:

Request {#40 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure {#284 ▶}
  #routeResolver: null
  +attributes: ParameterBag {#42 ▶}
  +request: ParameterBag {#48 ▶}
  +query: ParameterBag {#48 ▶}
  +server: ServerBag {#44 ▶}
  +files: FileBag {#45 ▶}
  +cookies: ParameterBag {#43 ▶}
  +headers: HeaderBag {#46 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/listing/preview"
  #requestUri: "/listing/preview"
  #baseUrl: ""
  #basePath: null
  #method: "GET"
  #format: null
  #session: null
  #locale: null
  #defaultLocale: "en"
}

then I tried dd($request->pathInfo) but it prints null when it should print "/listing/preview"? How do I access these values?

0 likes
2 replies
davielee's avatar
davielee
Best Answer
Level 11

Hey @maxnb you can actually call one of two methods to get that protected property.

$request->getPathInfo();

// or ...

$request->path();

pathInfo is a protected property and the Request class doesn't implement its __get() method in the way you would need it. Instead just use the methods above and you should be good to go.

2 likes
nikocraft's avatar

@ craigpaul Thanks man, didn't know about that. Learn something new every day here at forums :)

1 like

Please or to participate in this conversation.