Edit report at http://bugs.php.net/bug.php?id=53782&edit=1
ID: 53782 User updated by: david at grudl dot com Reported by: david at grudl dot com Summary: foreach throws irrelevant exception Status: Bogus Type: Bug Package: PDO related Operating System: Windows 7 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: This is a serious bug in the PDO. Look at the example more closely. Variable $res has nothing to do with errenous query. Previous Comments: ------------------------------------------------------------------------ [2011-05-10 10:06:47] u...@php.net Running errenous query and not expecting exception is bogus. ------------------------------------------------------------------------ [2011-01-18 21:30:47] david at grudl dot com Description: ------------ Iteration using foreach throws "previous" and irrelevant exception. Exception is throwed after last iteration. Test script: --------------- $conn = new PDO("mysql:dbname=test"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $res = $conn->query('SELECT * FROM categories'); try { $conn->query('ERROR'); } catch (PDOException $e) { // exception is catched } foreach ($res as $k => $v); // now is throwed exception $e !!! Expected result: ---------------- do nothing ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53782&edit=1