Req #76841 [Opn->Wfx]: simple breaking structure for better code.

[email protected] Tue, 04 Sep 2018 23:28:22 +0000
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=76841&edit=1

 ID:                 76841
 Updated by:         [email protected]
 Reported by:        leon at valkenb dot org
 Summary:            simple breaking structure for better code.
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            PHP Language Specification
 PHP Version:        Next Minor Version
 Block user comment: N
 Private report:     N

 New Comment:

This is called a function. http://php.net/manual/en/functions.user-defined.php 

function foobar() {
  if (!check1()) {
    return;
  }
  if (!check2()) {
    return;
  }
  baz();
}

You could also throw exceptions  etc


Previous Comments:
------------------------------------------------------------------------
[2018-09-04 23:23:23] leon at valkenb dot org

Description:
------------
I'd like to see something  like this in PHP (and all languages)

procedure{

	// Check simple statement
	if ($a = $b){
		break;
	}

	// Check complex statement
	if ( ($a != $b) && ($c > $b) ) {
		break;
	}

	// All checks succeed. Do something.
	something();
}

I write a good amount of code, and one of the annoyng things is not being able to simply create a process that can be broken out of without a loop.
Often i will use a switch / case, but this is not a tidy solution since there is oten no requirement for a case.

Test script:
---------------
procedure{ // or could be just proc. I couldn't think of a better word

	// Check simple statement
	if ($a = $b){
		break;
	}

	// Check complex statement
	if ( ($a != $b) && ($c > $b) ) {
		break;
	}

	// All checks succeed. Do something.
	print "Hello"
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76841&edit=1