VSCode, PHP Debug, & Docker – won’t show members of arrays or complex objects

Scenario:

  • PHP code runs in a container in Docker Desktop on my laptop.
  • An exact copy of the same code lives in a directory on my laptop (with a mechanism to sync any changes between my laptop copy and the container copy, but I believe that detail is probably irrelevant here).
  • "Listen for XDebug" is successful in stopping at breakpoints and at displaying active variables.

Problem:

  • When the debugger shows the active variables – either in the variables pane or by hovering over them in source code – I can only ever see a one-line summary. This is OK for primitives, but it’s unhelpful for collections or other complex objects.
  • Expanding an array variable with multiple elements shows no children.
  • Expanding an object variable shows no members.

Environment:

  • Consistent over multiple versions of VS Code over the past year
  • PHP Debug extension is kept up to date.
  • Consistent over multiple versions of PHP 7.x over the past year
  • This happens on both Windows and Mac laptops

What I’ve tried:

  • Ensure the exact same version of PHP is installed on both the Docker container and the laptop.
  • I’ve tried the following settings (to no avail) to try to force children to show:
            "xdebugSettings": {
                "max_children": -1,
                "max_data": -1,
                "max_depth": 5,
                "show_hidden": 1,
                "extended_properties": 1
              }
  • In the Debugger Console, I can enter details like $array_variable['member'] and see specific members, as long as I know what the member names are.
  • In the Debugger Console, I can json_encode($array_variable) and see members that are primitives or other arrays. This is somewhat helpful, but it’s not always a good representation of the variable’s contents.
  • I’ve turned on XDebug logging, and it creates a LOT of noise. I haven’t found anything useful in there to help me figure out what’s (not) happening.

Is anyone else using PHP Debug in VS Code on their host workstation to debug PHP running in a container? Have you figured out how to see the contents of complex variables?

Source: Docker Questions

LEAVE A COMMENT