我写了一个查看电子邮件不同部分的课程。一个功能是通过检查文件名是否存在于其属性数组中来确定每个部分是否是文件。
我的支票如下:
if (array_key_exists("filename",$body_part->d_parameters)) {
// do stuff
}
但是我在日志中不断收到此错误,因为如果该部分不是文件(标题,正文等),则没有名为“filename”的数组键。
PHP Notice: Undefined property: stdClass::$d_parameters in mail.php
PHP Warning: array_key_exists() expects parameter 2 to be array, null given in mail.php
答案 0 :(得分:1)
第一个错误是因为$body_part->d_parameters
在您引用它时不存在。
第二个错误是因为当您将$body_part->d_parameters
传递给array_key_exists()
isset()
不是一个数组
解决方案:在尝试将object属性传递给函数之前,请使用is_array()
和if ( isset($body_part->d_parameters) and is_array($body_part->d_parameters) and array_key_exists("filename",$body_part->d_parameters)) {
// do stuff
}
。
@Autowired
private EmployeeDAO employeeDAO;
private final Logger logger = LoggerFactory.getLogger(MainRestController.class);
@RequestMapping("/")
public String newHome(Model Employee){
return "newHome";
}
// call http://<host>/newHome.jspjsp or just http://<host>/hello
/*
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String newHome(Model employee) {
employee.addAttribute("myObject", new MyObject("helloWorld"));
return "newHome";
}