dump()函数导致内存异常
我正在研究基于Symfony 6 的项目。在调试期间,我添加了{{  dump()}}}
方法中的twig模板。这导致了一个脱离存储器
异常。即使使用最基本的模板和控制器,错误也是相同的:
// .../SomeProject/src/Controller/TestController.php
class TestController extends AbstractController {
public function dashboard(Request $request): Response {
return $this->render('dump.html.twig');
}
}
// .../SomeProject/templates/Controller/dump.html.twig
{{ dump() }}
// Error
Fatal error: Allowed memory size of 17179869184 bytes exhausted (tried to allocate 12882821120 bytes) in ...SomeProject/vendor/twig/twig/src/Extension/DebugExtension.php on line 57
Fatal error: Nesting level too deep - recursive dependency? in ...SomeProject/vendor/symfony/event-dispatcher/EventDispatcher.php on line 163
我已经检查了所有服务,控制器等。对于可能的递归依赖性,但我找不到。另外,我不确定,如果服务中不涉及的服务中的递归依赖性甚至很重要。 他们是吗?
那么,这是Symfony中的(已知的)错误(已知的解决方法)吗?还是我项目中的错误?我可以执行哪些步骤来识别和解决问题?
编辑
评论中请求的更多信息:
{{ dump() }} // out of memory
{{ dump(foo) }} // string(15) "this is as test"
{{ foo }} // Variable " foo" does not exist.
{{ _context|keys|dump }} // Unknown "dump" filter. Did you mean "yaml_dump"?
{{ _context|keys|yaml_dump }} // %array% [foo, app]
{{ _context|yaml_dump }} // %array% { test: 'this is as test', app: null }
{{ dump(_context|keys) }} // array(2) { [0]=> string(4) "test" [1]=> string(3) "app" }
{{ dump(_context) }} // out of memory
edit2
ok,<代码>变量“ foo”的问题。已解决。看来{{foo}}
之前存在一些非法字符,而不是空间。修复此操作后,它将正确输出。
但是,主要问题仍然是,为什么dump()
不起作用。在一个旧的Symfony 3项目中,这可以正常工作,并对完整上下文进行了很好的概述。这很方便,可以看到可用的信息。
I am working on a Symfony 6
based project. During debugging I have added {{ dump() }}
method to a twig template. This resulted in an Out of Memory
exception. Even with the most basic template and controller the error is the same:
// .../SomeProject/src/Controller/TestController.php
class TestController extends AbstractController {
public function dashboard(Request $request): Response {
return $this->render('dump.html.twig');
}
}
// .../SomeProject/templates/Controller/dump.html.twig
{{ dump() }}
// Error
Fatal error: Allowed memory size of 17179869184 bytes exhausted (tried to allocate 12882821120 bytes) in ...SomeProject/vendor/twig/twig/src/Extension/DebugExtension.php on line 57
Fatal error: Nesting level too deep - recursive dependency? in ...SomeProject/vendor/symfony/event-dispatcher/EventDispatcher.php on line 163
I have checked all services, controllers, etc. for possible recursive dependencies but I could find none. Additionally I am not sure, if recursive dependencies within services which are not involved in serving this request would even matter. Do they?
So, is this a (known) bug in Symfony (with a known workaround)? Or some error in my project? What steps to identify and resolve the problem could I perform?
Edit
Some more information requested in the comments:
{{ dump() }} // out of memory
{{ dump(foo) }} // string(15) "this is as test"
{{ foo }} // Variable " foo" does not exist.
{{ _context|keys|dump }} // Unknown "dump" filter. Did you mean "yaml_dump"?
{{ _context|keys|yaml_dump }} // %array% [foo, app]
{{ _context|yaml_dump }} // %array% { test: 'this is as test', app: null }
{{ dump(_context|keys) }} // array(2) { [0]=> string(4) "test" [1]=> string(3) "app" }
{{ dump(_context) }} // out of memory
Edit2
OK, the problem that Variable " foo" does not exist.
is resolved. It seems that there was some illegal character instead of a space just before {{ foo }}
. After fixing this, it outputs correctly.
However, the main question is still, why dump()
does not work. In an old Symfony 3 project this works just fine and outputs a great overview of the complete context. This is pretty handy to see what information is available.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论