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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 03:01:30 2024 UTC