php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46158 Break out of compound blocks.
Submitted: 2008-09-23 11:01 UTC Modified: 2008-09-23 11:20 UTC
From: kok at nachon dot nl Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.6 OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kok at nachon dot nl
New email:
PHP Version: OS:

 

 [2008-09-23 11:01 UTC] kok at nachon dot nl
Description:
------------
I read in Bug #29287 about breaking out of loops and was wondering if anyone considered breaking out of a generic compound block. This would satisfy the need for error handling without goto.

Example:
function connect() {

{ //start compound block

if (!mysql_connect('host', 'user', 'pass)) break; //break out
if (!mysql_select_db('database')) break; //break out
return;

}

$code = mysql_errno();
$msg = mysql_error();
throw new Exception($msg, $code);

}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-23 11:20 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Adding this functionality would break scripts, so we'd need a new keyword which has issues...

A suggested work-around is like that:

if ($foo) {
    do {
        if (do_something()) {
            break;
        }
        do_more();
    } while (0);
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Sep 16 20:00:01 2025 UTC