简体   繁体   English

重新安装forum mod时出现“ 8:Undefined offset:1”错误

[英]Getting an “8: Undefined offset: 1” error when re-installing forum mod

To preempt this being marked as a duplicate question, please understand that I have zero experience with PHP coding/syntax and I am struggling to apply a general answer to my specific problem. 为了避免将此问题标记为重复的问题,请理解我对PHP编码/语法的经验为零 ,并且正在努力为我的特定问题提供一个一般性的答案。 I think I've figured out where the problem is coming from, but I'm not even 100% about that, so I am seeking the assistance of someone who can help guide me through figuring this out for certain. 我想我已经找出问题的根源了,但是我什至没有100%知道,所以我正在寻求可以帮助我确定问题的人的帮助。

We are installing a dice rolling mod to a Simple Machines forum. 我们正在将骰子滚动模块安装到Simple Machines论坛。 The first install went smoothly, no problems. 第一次安装进行顺利,没有问题。 We wanted to change some of the mod's formatting, so we uninstalled it, changed the files, and reinstalled it. 我们想更改某些mod的格式,因此我们将其卸载,更改文件并重新安装。 After reinstallation, posting new topics or make replies resulted in a . 重新安装后,发布新主题或进行回复导致。 When we disabled the mod, we could reply and post new topics as usual. 禁用该模块后,我们可以照常答复和发布新主题。

After some hunting, we found this in our error log; 经过一番寻找,我们在错误日志中找到了这个;

http://irate-pirate.org/forums/index.php?action=admin;area=packages;get;sa=browse;server=1;relative=posting  
8: Undefined offset: 1  
File: /home4/iratepir/public_html/forums/Sources/Subs-Package.php  
Line: 1503

We found the Subs-Package.php file, and here is the surrounding code: 我们找到了Subs-Package.php文件,下面是周围的代码:

1501      // Build an array of parts.
1502        $versions[$id] = array(
1503             'major' => (int) $parts[1],
1504             'minor' => !empty($parts[2]) ? (int) $parts[2] : 0,
1505             'patch' => !empty($parts[3]) ? (int) $parts[3] : 0,
1506             'type' => empty($parts[4]) ? 'stable' : $parts[4],
1507             'type_major' => !empty($parts[6]) ? (int) $parts[5] : 0,
1508             'type_minor' => !empty($parts[6]) ? (int) $parts[6] : 0,
1509             'dev' => !empty($parts[7]),
1510        );
1511   }

So, after looking at this post , I think(???) need to add: 因此,看完这篇文章后 ,我认为(???)需要添加:

//isset()
$value = isset($array['my_index']) ? $array['my_index'] : '';
//array_key_exists()
$value = array_key_exists('my_index', $array) ? $array['my_index'] : '';

to the code I've found in the Subs-Package.php file. 到我在Subs-Package.php文件中找到的代码。 I'm guessing that I add this before the line the error was found in. 我猜想我在发现错误的行之前添加了这个。

I'm also guessing some of these variables need to be changed to match the parts from our code, but I don't know which variables. 我还猜想其中一些变量需要更改以匹配我们代码中的部分,但是我不知道哪个变量。

Any help would be absolutely fantastic, and I hope I've given enough information! 任何帮助都将非常棒,我希望我能提供足够的信息!

You need to check if the $parts array indexes are set or not. 您需要检查$parts数组索引是否已设置。 It can happen that the array $parts does not exists. 可能发生数组$parts不存在。 So, you need to add isset to handle such cases. 因此,您需要添加isset来处理此类情况。

For eg 例如

1501      // Build an array of parts.
1502        $versions[$id] = array(
1503             'major' => isset($parts[1]) ?(int) $parts[1] : 0,
1504             'minor' => isset($parts[2]) ?(int) $parts[2] : 0,
1505             'patch' => isset($parts[3]) ?(int) $parts[3] : 0,
1506             'type' => isset($parts[4]) ?(int) $parts[4] : 0,
1507             'type_major' => isset($parts[5]) ?(int) $parts[5] : 0,
1508             'type_minor' => isset($parts[6]) ?(int) $parts[6] : 0,
1509             'dev' => isset($parts[7]) ?(int) $parts[7] : 0,
1510        );
1511   }


isset() will check if the referenced value is defined or not. 
empty($parts[index]) can give error in cases where array $parts is not defined 
as it will try to check the value that doesn't exists.

This code will work even if $parts array is not defined. 即使未定义$parts数组,此代码也将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM