php 使用 arrayObject 进行致命异常处理
需要有关 arrayObject 异常处理的帮助。我正在迭代一系列对象,但是当偏移结束时会发生致命异常。代码是:
while ($c <= 10) {
$num = 1;
$b = $c-$num;
$object_to_iterate = $q[$b];
$obj = new ArrayObject ($object_to_iterate);
iterateObject($obj);
$c ++;
}
错误是:
Fatal error: Uncaught exception 'InvalidArgumentException'
任何帮助都会很棒。
Need help with exception handling for arrayObject. I'm iterating through a series of objects but when the offset ends fatal exception occurs. The code is:
while ($c <= 10) {
$num = 1;
$b = $c-$num;
$object_to_iterate = $q[$b];
$obj = new ArrayObject ($object_to_iterate);
iterateObject($obj);
$c ++;
}
The error is:
Fatal error: Uncaught exception 'InvalidArgumentException'
Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自手册:
现在正如@BoltClock所说:真的很难在不知道 b、c、q 和 num 的情况下弄清楚是什么,但如果 q 是一个数组,那么
可能只是一个字符串?然后
有一个不是对象或数组的参数?
也许对
$object_to_iterate
执行var_dump()
,并检查它是数组还是对象。from the manual:
Now as @BoltClock said: it is really hard to figure out without knowing what b, c, q and num are, but if q is an array, then
might be just a string? And then
has an argument that is not an object or array?
Maybe do a
var_dump()
on that$object_to_iterate
, and check is it is an array or object.$c 开头是什么?如果为 0(很可能),则 $b = -1,并且您试图获取 $q[-1],而该值很可能不存在。因此,您并没有真正将任何内容传递给 ArrayObject 构造函数。
What does $c start as? If 0 (which is likely), then $b = -1 and you're trying to get $q[-1], which, again, likely doesn't exist. So you're not really passing anything to the ArrayObject constructor.
好的,我不知道这是否是最好的方法,但我使用了以下代码:
它可以通过
OK I don't know if this is the best way to do it but I used the following code:
It works through