I am using Twig's dump function in Symfony2. I have configured Symfony according to its instructions.
I have a page variable, and an orders array. dump works on page, but not orders. When I call it on orders, I get a white screen - no php errors or anything. I have no idea how to debug this.
Any ideas?
A white (blank) screen in this case means the PHP fatal error: Allowed memory size exhausted. During my investigation, I found that twig uses thevar_dump function while I have VarDumper component installed.
I think its made to work along in case the VarDumper component is not installed, but twig's dump() function covered in symfony's VarDumper component documentation like a complex solution, that's strange.
So, using VarDumper's dump() function instead of native var_dump() solves the memory problem (because VarDumper limits result dump collection to adequate amount). Also VarDumper's dump() give more convenient results - you can click on tree leafs to show/hide its content.
vendor/twig/twig/lib/Twig/Extension/Debug.php
twig_var_dump functionvar_dump() calls to dump()
ob_start() + ob_get_clean() construction (which is needed
if you use var_dump() as it echoes data immideately, but dump() acting
more intelligent)OR
copy + replace the entire function using this:
function twig_var_dump(Twig_Environment $env, $context)
{
if (!$env->isDebug()) {
return;
}
$count = func_num_args();
if (2 === $count) {
$vars = array();
foreach ($context as $key => $value) {
if (!$value instanceof Twig_Template) {
$vars[$key] = $value;
}
}
dump($vars);
} else {
for ($i = 2; $i < $count; $i++) {
dump(func_get_arg($i));
}
}
}
PS: Question's asked in 2013, but I hope it helps because I had this problem now.
My context:
"symfony/symfony": "2.5.*"
"symfony/var-dumper": "~2.6"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With