How to get xdebug var_dump to show full object/array
When you enable Xdebug, your var_dump output often stops halfway through large structures, truncating arrays and objects with a message like .... This happens because Xdebug is designed by default to limit the amount of data it sends back to the browser. It treats massive dumps as performance hazards that can freeze the request or overwhelm the client.
The behavior you are seeingâwhere an array looks cut off immediately after the first few keysâis not a bug in your code or WAMP Server; it is a deliberate safety feature controlled by the xdebug.max_nesting_level and xdebug.var_dump_max_depth settings. In many configurations, specifically older versions like the one mentioned in the source material (php_xdebug-2.1.2), the default maximum depth for var_dump was set to 5 or 10. This means Xdebug will only print the first few levels of nesting before stopping.
To see the full structure, you must explicitly raise this limit. However, simply increasing the number is often not enough if the setting isn't applied correctly in your environment.
Adjusting xdebug.var_dump_max_depth
The primary configuration flag responsible for this truncation is xdebug.var_dump_max_depth. By default, this is set to a low integer (often 5). You need to increase this value to allow Xdebug to traverse deeper into your data structures.
In older versions of PHP and Xdebug (like v2.1.2), the most reliable way to change this is by editing the php.ini file located in your WAMP installation directory or by adding a directive to your project-specific php.ini. Add the following line:
xdebug.var_dump_max_depth = 50
You should set this value based on the maximum depth of your data structures. A value of 50 is usually sufficient for most debugging scenarios without risking memory exhaustion. If you are debugging a deeply nested JSON-like structure, you might need to go higher, but be cautious not to set it too high (e.g., 100+) unless necessary, as printing massive arrays can still cause browser hangs regardless of the depth limit.
Managing Nesting Levels vs. Variable Dump Limits
There is a second setting often confused with this one: xdebug.max_nesting_level. This controls how deep recursive functions can call each other (default is 1024). While related to stack overflows, it does not directly control the output of var_dump. However, in some very old configurations, if nesting limits were hit during the internal processing of the dump, output could be truncated. Ensure you check both settings:
xdebug.max_nesting_level = 1024
xdebug.var_dump_max_depth = 50
The Trade-Off: Performance vs. Visibility
Increasing these limits comes with a performance cost. When Xdebug captures a stack trace or generates a dump of a massive object, it has to serialize that entire structure into a string. If you enable dumping on every line of code (xdebug.dump = ALL), and then increase the depth limit, your application will slow down significantly.
The standard recommendation is to keep xdebug.dump restricted. Instead of dumping everything, let Xdebug only dump variables that are actually useful for debugging:
xdebug.dump = GLOBALS;REQUEST;COOKIE;SERVER;GET;POST;SESSION;FILES
With this configuration, var_dump will still truncate large arrays by default if they exceed the depth limit. To see the full content of a specific variable without slowing down the entire site, you can use xdebug.show_local_vars (if available in your version) or simply rely on IDE features like "Pretty Print" which often handle truncation better than raw HTML output.
Modern Alternatives and Best Practices
If you are working with modern PHP versions (7.x or 8.x), the Xdebug defaults have changed slightly, and the xdebug.var_dump_max_depth setting might not even be present in newer documentation. In those cases, the behavior is often handled by the underlying PHP engine's memory limits. However, since your source material references v2.1.2, the configuration approach described above is the correct path for that specific environment.
For production environments or high-traffic sites, relying on var_dump for large objects is generally discouraged regardless of the depth setting. Instead, consider using tools like Laravel's logging system or custom debuggers that stream data to a file rather than echoing it directly to the browser. This decouples debugging from the HTTP response time.
If you are building applications with frameworks like Laravel, ensure your php.ini settings persist across all environments. Sometimes, even if you set these values in php.ini, web servers running as services (like Apache or Nginx via PHP-FPM) might read a different configuration file. Verify that your active php.ini matches the one where you added the xdebug.var_dump_max_depth directive.
Finally, remember that increasing these limits does not fix issues caused by infinite recursion in your code. If an object references itself deeply without termination, raising the depth limit will only allow Xdebug to crash with a fatal error rather than showing you the structure. Always inspect the logic of your data generation before adjusting these safety nets.
