I am building an app with Symfony 2, and I am wondering, how could I handle errors when I try to read a index in an array that doesn't exist? Sadly this kind of errors don't throw exceptions, so I can't really use a try-catch block.
Example:
$test = array();
$test["323"]; // Undefined index error!
Please, ideas how to handle this errors?
Update: I have seen many solutions with isset. The problem with this is that I would have to do it with every single access to an array index. Can anyone offer me a more DRY solution?
if(isset($test["323"]))???or similar as fallback already. Using @ for suppressing notice logged to Symfony logger wasn't working in my case either. According to PHP doc @ isn't suppressing custom error handler being called. As stated in note on linked page this is up to that custom handler to obey individual suppression. Thus it is more related to Symfony than to PHP ... eventually this question is not a duplicate of linked thread either.