PHP 5.2 出现的Nesting level too deep - recursive dependency问题

Nextcloud升级后问题解决 Nextcloud服务器版本太低了,执行自动升级服务。结果出现问题了。如下: 1、 在数据表 “oc_share” 中无法找到索引 “share_with_index”。 在数据表 “oc_share” 中无法找到索引 “parent_index”。 在数据表 “oc_share” 中无法找到索引 “owner_index”。 在数据表 “oc_share” 中无法找到索引 “initiator_index”。 在数据表 “oc_filecache” 中无法找到索引 “fs_mtime”。 2、 数据库中的 阅读详情
在PHP 5.1下运行很好的PHP,移植到PHP5.2之后出现 Nesting level too deep - recursive dependency的问题。
对PHP我是不懂了,但让其正常运行是我的责任,于是google。
下面是找到的东西

http://www.phpdeveloper.org/news/6691

So, you've just upgraded to PHP 5.2 and all is going well until you come across a page in your application that gives the message "Nesting level too deep - recursive dependency?". With such a vague error message, you might have trouble locating the source of the problem. Thankfully, someone's already been there and figured out the issue - Richard Lord.
I installed PHP 5.2 on one of my testing servers today and a couple of bits of code that previously worked fine in version 5.1.6 threw fatal errors in the new version. The error message was "Nesting level too deep - recursive dependency?" and it took a little time to track down the root of the problem. Here's what I'd done wrong.

Basically, his problem was using the "non-strict" evaluation for checking if two objects were equal to each other (== instead of ===). This compares everything about them, down to the properties - even if they're references to other properties inside of the same class (which is where the problem lies).

So, the fix is simple - === instead of == when comparing those objects. You'll be happier for the change.


 

http://www.bigroom.co.uk/blog/php-nesting-level-too-deep-recursive-dependency/


I installed PHP 5.2 on one of my testing servers today and a couple of bits of code that previously worked fine in version 5.1.6 threw fatal errors in the new version. The error message was “Nesting level too deep - recursive dependency?” and it took a little time to track down the root of the problem. Here’s what I’d done wrong.

In PHP there are two comparison operators, == and ===. It’s generally known that the first is not strict about type but the second is. So, for example

echo ( false == 0 ); // true
echo ( false === 0 ); // false
    - 0 is an integer and false is a boolean

My problem arose from using non-strict typing with objects.

$a = new MyObj();
$b = new MyObj();
if( $a == $b )
…

I hadn’t considered what I was doing with this code. When comparing two objects using the non-strict comparison operator (==) PHP compares all the properties of the objects and if they match the objects are deemed to be equal. If they don’t match they are not equal. In effect, we have a recursive comparison of all the properties of each object, and all their properties, etc. until we reach basic data types like strings and integers.

If, however, we use strict comparison (===), PHP will check whether the two objects are exactly the same object, not just objects with the same properties.

class MyObj
{
    public $p;
}

$a = new MyObj();
$b = new MyObj();
$c = new MyObj();
$a->p = 1;
$b->p = 1;
$c->p = 2;
echo ( $a == $c ); // false
echo ( $a == $b ); // true
echo ( $a === $b ); // false

The problem arises if you have circular references in your objects properties. So, for example

class MyObj
{
    public $p;
}
class OtherObj
{
    public $q;
}

$a = new MyObj();
$b = new OtherObj();
$a->p = $b;
$b->q = $a; // the circular reference: $a->p->p === $a

$c = new MyObj();
$d = new OtherObj();
$c->p = $d;
$d->q = $c;// another circular reference: $c->p->p === $c

echo ( $a == $c ); // Fatal error:
    Nesting level too deep - recursive dependency?

In order to compare $a to $c, PHP must compare their properties. So the logic in PHP goes something like this: $a == $c if $a->p == $c->p if $a->p->p == $c->p->p if $a->p->p->p == $c->p->p->p etc. indefinitely.

PHP 5.1 seemed to smooth over the problem somehow (probably after a certain level of recursion it simply returned false) - and usually it worked out fine. PHP 5.2 correctly produces the fatal error above.

Once you know the problem, the solution is easy - use strict comparison.

echo ( $a === $c ); // false (and no error)

The strict comparison will simply check whether the two objects are at the same location in memory and so doesn’t even look at the values of the properties.

N.B. The same problem can arise when using the negated comparison operators (use !== instead of !=) and when using in_array (use in_array’s third parameter to indicate strict comparison).


总之问题是解决了,是因为语言不规范所致。将==转为===, 将!=转为!==,彻底好了。

ZendFramework1.0 PDF开发中-Nesting level too deep的解决 NULL 博文链接:https://vb2005xu.iteye.com/blog/375392 立即下载

相关推荐

MATLAB MinGW-w64 C/C++ 编译器 手动安装配置

根据Matlab版本与MinGW版本对应关系,手动安装、配置并测试MinGW

zjh2883的博客 7366

Nesting level too deep - recursive dependency?

php7 使用双向循环链表解决约瑟夫问题时遇到的问题,下面是报错位置的代码: 在StackOverflow上相关问题下面有一个解答是这么描述的: 翻译过来的意思就是: 如果两个对象共享一个属性作为其值,PHP将在这些属性对象之间进行相同的==比较。现在,只要这些属性对象是递归的(例如,自引用对象),比较也会向下递归,直到达到最大嵌套级别 而我的那段代码 循环链表正是 自引用对象 ,所以出现这个问题, 解决方法上面图片也提到了, 就是自引用对象相互比较的时候...

shi588266的博客 626

FreeCAD MCP实战:用自然语言驱动AI建模,效率提升10倍

MCP(Model Context Protocol)是一种让AI模型调用外部工具和数据的协议标准,通过标准化通信层解决AI与CAD软件之间的交互难题。其原理是向AI暴露工具清单,AI根据自然语言需求自动选择工具并填充参数。在工程实践中,这一技术显著降低了CAD建模门槛,将重复性操作从手动点击转为语音指令,适用于批量零件生成、参数化设计等场景。FreeCAD作为开源CAD,凭借开放的Python API和脚本化能力,成为落地MCP的理想平台。本文基于FreeCAD MCP的实操经验,分享环境搭建、自然语言建

weixin_31188927的博客 354

Error #include nested too deeply

出现 Error #include nested too deeply 原因是: 头文件相互包含。 例如,一个工程中bsp.h 包含 LocDongle.h, LocDongle.h又包含bsp.h, 编译时就会报Error #include nested too deeply 。 解决办法: 1、将两个头文件共用的那一部分抽出来单独建一个头文件。 2、加预处理#ifndef.

ysdaniel的专栏 3万+

Arduino IDE 2配置ESP32-S3工程全指南

嵌入式开发中,Arduino框架通过硬件抽象层(HAL)大幅降低MCU入门门槛,其核心在于板级支持包(BSP)与底层构建系统(如ESP-IDF)的精准协同。理解CPU频率、Flash模式、分区表、PSRAM等关键配置,本质是掌握SoC时钟树、SPI Flash通信协议、内存映射与FreeRTOS调度机制的技术原理。这些参数不仅决定固件能否启动,更直接影响功耗、实时性、OTA升级与大容量应用(如LVGL、TFLite Micro)的可行性。本文以ESP32-S3为例,聚焦Arduino IDE 2.x环境下从

root9的博客 792

多维时空数据介绍(4)多维栅格数据构建

上图中包含了经度、纬度和时间三个维度,其变量为经度、纬度、时间以及降雨量,对应的变量单位为东经多少度、北纬多少度、阳历1895-1-1日开始多少天以及每年降雨多少毫升,其中经度数值4个、纬度数值3个、时间数值2个都是一维的数据,而降雨量是一个包含经度、纬度、时间的三维数组,数值有4*3*2=24个。在GeoScene 中NetCDF数据可以用做多种多维时空数据的数据源,进行创建、可视化和分析,它可以是多维栅格数据、时空立方体,还可以是体元图层,区别在于其所要表示的内容和目的。变量又分为坐标变量和属性变量。

你好,我是小张同学! 1296

fatal error C1061: compiler limit : blocks nested too deeply 原因以及解决办法

文章目录一.问题描述二.原因三.解决办法1.将深层嵌套的代码分解为从原始上下文调用的函数2.面向对象的方法3.利用switch替换四.参考文献 写在前面的话:   续接上次的ASN.1继续更新,这是项目文件在编译时候遇到的错误,现在总结一下 一.问题描述 在xx.cpp的项目文件中,需要在原来的else if架构中再添加一行该结构来匹配字符串,但是在编译时候出现fatal er...

ryhybx的博客 3575

深度学习-176-知识图谱技术之langchain与neo4j的嵌入向量Neo4jVector

使用Neo4jVector将输入的文档向量化,并创建向量索引,然后进行语义检索。

qq_20466211的博客 445

Keil报错error:#include nested too deeply

Keil报错error:#include nested too deeply

dahuivolition的博客 857

HTML满屏跳动的爱心(完整代码)

HTML语言实现满屏跳动爱心的完整代码。

AIGC 12万+

OpenCASCADE:写IGES

OpenCASCADE:写IGES程序涵盖的领域流程说明初始化过程设置翻译参数执行 Open CASCADE Technology 形状转换编写 IGES 文件将开放级联技术形状映射到 IGES 实体曲线表面拓扑实体——人脸模式下的平移公差管理在 IGES 文件中设置分辨率代码架构调用图例子 程序 您可以通过以下步骤将 OCCT 形状转换为 IGES 实体: 初始化进程。 设置翻译参数, 执行模型翻译, 写入输出 IGES 文件。 您可以在写入文件之前转换多个形状。每个形状都将是 IGES 模型中的根实体。

希望我的博客,能帮上你解决学习中工作中所遇到的问题 940

mac下#include nested too deeply错误处理

如果遇到下面这种错误: /usr/local/include/stdint.h:2:10: error: #include nested too deeply #include <stddef.h> ^ /usr/local/include/stdint.h:59:11: error: #include nested too deeply # in...

章志强的专栏 4860

keras tensorflow 的lstm的新冠疫情感染人数预测 附完整代码数据 可直接运行

keras tensorflow 的lstm的新冠疫情感染人数预测 附完整代码数据 可直接运行

857

error: #include nested too deeply #include “glog/vlog_is_on.h“

这种情况一般是有两种一种是A.h中引入了B.h,然后是B.h中引入A.h了,就是嵌套引用,这种情况可以看一下下述链接的解决方法。后来排查我是在A.h中不小心又#include <A.h>

weixin_45533366的博客 750

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Nesting level too deep

在用PHP模拟循环链表结构时,给初始化的链表插入一个元素没有问题,但是用for循环插入10个元素,居然报出了如下错误: Fatal error: Nesting level too deep - recursive dependency 1 function append($data) { 2 $link = $this->header; 3 ...

aochuang7039的博客 355

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

论文阅读Recursive Deep Models

http://nlp.stanford.edu/~socherr/EMNLP2013_RNTN.pdf Recursive Deep Models for Semantic Compositionality Over a Sentiment Treebank 递归的深度模型在情感语料库的语义组合上的应用 本文主要提出了一个递归神经张量网络(Recursive Neural

周周的专栏 2116

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Fatal error: Maximum function nesting level of '100' reached, aborting!

今天访问PHP网站如下以下错误:  Fatal error: Maximum function nesting level of '100' reached, aborting! 原因分析: 这个问题是由于你启用了xdebug,而xdebug默认设置了函数最大嵌套数为100 解决办法: 找到php.ini文件,找到xdebug

chenhualeguan的专栏 2052
上一篇: 配置apache和mysql到多用户状态
下一篇: 免费打印pdf文件
DigBug
博客等级 码龄20年 15粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址