致命错误:嵌套级别太深-递归依赖项? [英] Fatal error: Nesting level too deep - recursive dependency?

查看:75
本文介绍了致命错误:嵌套级别太深-递归依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的嵌套对象层次结构,所有子对象(在父类中存储了对象的数组)都包含一个链接回其父对象的属性:非常简单明了,没有任何实际问题.如果我对层次结构中的任何对象执行var_dump,则将在转储中获得与我期望的完全相同的递归引用.

I have a complex hierarchy of nested objects, with all of the child objects (stored an array of objects in the parent class) containing a property linking back to their parent: fairly simple and straightforward, with no real problems. If I do a var_dump of any object in the hierarchy, I'll get a recursive reference in the dump, exactly as I'd expect.

FIRSTGEN 
   _children array of objects of type SECONDGEN
      SECONDGEN #1
         _parent object of type FIRSTGEN
         _children array of objects of type THIRDGEN
            THIRDGEN #1
               _parent object of type SECONDGEN
            THIRDGEN #2
               _parent object of type SECONDGEN
      SECONDGEN #2
         _parent object of type FIRSTGEN
         _children array of objects of type THIRDGEN
            THIRDGEN #3
               _parent object of type SECONDGEN

我最近在该层次结构中添加了一些新元素,但它们没有遵循完全相同的模式.它们存储在顶级父对象中的对象数组中,但是包含一个将它们链接回的链接,而不是链接到其父链接,而是链接到同级链接.现在,当我执行var_dump时,出现致命错误:嵌套级别太深-递归依赖项?".

I've recently added some new elements to that hierarchy, and they don't follow quite the same pattern. They are stored in an array of objects in the top-level parent, but contain a property linking them back, not to their parent, but to a sibling. When I do a var_dump now, I get a "Fatal error: Nesting level too deep - recursive dependency?".

FIRSTGEN 
   _children_1 array of objects of type SECONDGEN_1
      SECONDGEN_1 #1
         _parent object of type FIRSTGEN
         _children array of objects of type THIRDGEN
            THIRDGEN #1
               _parent object of type SECONDGEN_1
            THIRDGEN #2
               _parent object of type SECONDGEN_1
      SECONDGEN_1 #2
         _parent object of type FIRSTGEN
         _children array of objects of type THIRDGEN
            THIRDGEN #3
               _parent object of type SECONDGEN_1
   _children_2 array of objects of type SECONDGEN_2
      SECONDGEN_2 #1
         _parent object of type SECONDGEN_1

除var_dump()之外,代码中的所有其他内容均正常工作.我尝试创建一个更简单的示例来演示该问题,以便在提出此问题时可以提供一个示例.但无法在短期测试中复制它,只能在我更复杂的代码中复制.

Everything else within the code works correctly, with the exception of that var_dump(). I've tried creating a simpler example to demonstrate the problem, so that I could provide an example when asking this question; but haven't been able to replicate it in a short test, only within my more complex code.

我知道解决方案是重构关系,以便将我的_children_2 SECONDGEN_2对象的数组保存在适当的SECONDGEN_1父级中,从而使父级关系正确" ...我已经开始这样做. 但是,我对该错误感兴趣,并想知道是否有人遇到过该错误(以及您自己如何处理).

I know that the solution is to refactor the relationship so that my _children_2 array of SECONDGEN_2 objects is held in the appropriate SECONDGEN_1 parent, making the parent relationship "correct"... I've already started doing this. However, I'm intrigued by the error, and wondered if anybody else had encountered it (and how you dealt with it yourself).

推荐答案

类似于自引用代码中的PHP限制,并尝试使用print_rvar_dumpvar_export显示它,或使用它进行搜索in_array.基本上,这些功能没有办法知道在循环引用对象的情况下在哪里停止递归.

Looks like a PHP limitation in self-referencing code and trying to display it with print_r, var_dump, var_export, or search through it with in_array. Basically there's no way for those functions to know where to stop recursing if an object is referenced cirularly.

根据此错误报告 其他错误报告也提到,还有更多测试用例.我想说的是,如果仅在var_dump中触发此操作,则不必为此太担心.如果这是出于调试目的,那么我绝对赞同Wrikken关于xdebug的建议.

Other bug reports mention it too, with some more test cases. I'd say that if this is only triggered in var_dump you shouldn't worry too much about it. I definitely second Wrikken's suggestion about xdebug if this is for debugging purposes.

这篇关于致命错误:嵌套级别太深-递归依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆