在执行过程中,所有错误都会保存到一个数组中,如下所示:
$this->errors[$section] = $e->getMessage();问题是,在执行之后,我必须发布所有的部分,包括那些实验了错误与错误连接的部分。当我尝试:
echo $this->errors[$section];这是我得到的警告:
Warning: Illegal offset type in ....在Dynamic access to a PHP array上描述的解决方案没有帮助。
发布于 2012-08-11 04:42:13
在使用索引之前,请检查索引是否有效:
if (array_key_exists($section, $this->errors) ) {
echo $this->errors[$section];
}发布于 2012-08-11 04:45:19
如果您还没有设置$section,那么PHP将不知道返回什么。
假设您的部分是具有某种ID号或字符串的数组:
$errors[$section['id']] = $e->getMessage();
...
foreach($errors as $error){
print_r($error);
}我有一种感觉,您的问题在于$section在第二个代码块中不再设置为您想要的内容。
https://stackoverflow.com/questions/11908937
复制相似问题