0

好吧,就像标题一样,由于这些事情,我遇到了问题。问题是由于 X 行而发生的,它位于SitePoint 的 Tree Traversalwhile ($right[count($right)-1]<$row['rgt']) {的函数 display_tree 中。

该功能运行良好,但我不知道为什么它突然开始抛出这个致命错误。

我尝试使用error_reporting(-1);以了解可能导致错误的原因,新的错误日志显示我多次收到 PHP 通知,就像在未完成的循环中一样,直到我收到内存不足错误。

奇怪的是,直到两天前,这一直运行良好,因为当我拔出头发来破译导致问题的原因时。

有什么方法可以准确了解导致问题的原因?或者可能是其他一些有用的提示?

这是它的条件内的while循环:

if (count($right)>0) {
$j=0;
while ($right[count($right)-1]<$row['rgt']) {  
  array_pop($right);
   $j++;
  }   
}

多谢你们。

4

2 回答 2

2

对于初学者来说,通知Undefined offset: -1表明数组$right是空的。

编辑:在你的循环中,你$array什么都没有……保证会失败。需要在数组变空之前停止循环。

这将解决眼前的问题,但(本身)不太可能使您的程序正常工作:

while ($right && $right[count($right)-1]<$row['rgt']) {

由于end($right)返回相同的值$right[count($right)-1],我们可以将其简化为:

while ($right && end($right) < $row['rgt']) {
于 2011-02-15T09:24:42.450 回答
0

If you are following Site Points function completely, I imagine the reason for the error is that your tree is corrupt.

Even more reason to suggest your tree is corrupt, is that you say the code was working fine a few days ago...

I've testing your function on the Site Point tree and it seems to run fine.

The function doesn't do any checking for a corrupt tree. The while loop condition you first pointed out should never reach a situation where $right is empty.

于 2011-02-15T09:35:21.407 回答