php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53782 foreach throws irrelevant exception
Submitted: 2011-01-18 21:30 UTC Modified: 2011-05-16 17:38 UTC
From: david at grudl dot com Assigned: johannes (profile)
Status: Closed Package: PDO related
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
 [2011-01-18 21:30 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-10 10:06 UTC] uw@php.net
-Status: Open +Status: Bogus
 [2011-05-10 10:06 UTC] uw@php.net
Running errenous query and not expecting exception is bogus.
 [2011-05-10 14:37 UTC] david at grudl dot com
This is a serious bug in the PDO. Look at the example more closely. Variable $res has nothing to do with errenous query.
 [2011-05-12 16:31 UTC] vrana@php.net
-Status: Bogus +Status: Re-Opened
 [2011-05-12 16:31 UTC] vrana@php.net
This seems like a real bug, example is correct.
 [2011-05-16 17:37 UTC] johannes@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=311088
Log: - Fix Bug #53782 (foreach throws irrelevant exception)
 [2011-05-16 17:38 UTC] johannes@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: johannes
 [2011-05-16 17:38 UTC] johannes@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:50 UTC] laruence@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0179c5a0e604f4b2181740fd1a0d6ed1f2a887f6
Log: - Fix Bug #53782 (foreach throws irrelevant exception)
 [2012-07-24 23:41 UTC] rasmus@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0179c5a0e604f4b2181740fd1a0d6ed1f2a887f6
Log: - Fix Bug #53782 (foreach throws irrelevant exception)
 [2013-11-17 09:38 UTC] laruence@php.net
Automatic comment on behalf of johannes
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0179c5a0e604f4b2181740fd1a0d6ed1f2a887f6
Log: - Fix Bug #53782 (foreach throws irrelevant exception)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC