Bug #40712 [Com]: return after "or"
| From: | damien dot bezborodov at staff dot nuskope dot com dot au | Date: | Wed, 19 Oct 2016 01:56:45 +0000 |
| Subject: | Bug #40712 [Com]: return after "or" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204905@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=40712&edit=1
ID: 40712
Comment by: damien dot bezborodov at staff dot nuskope dot com
dot au
Reported by: s dot j dot t dot mocking at students dot uu dot nl
Summary: return after "or"
Status: Not a bug
Type: Bug
Package: *Programming Data Structures
Operating System: Linux (Debian Testing)
PHP Version: 5.2.1
Block user comment: N
Private report: N
New Comment:
This would be a useful feature. Compare the clarity of the following examples where every line
requires error checking: 1) using IF statements, 2) using invalid "or return false"
syntax, or 3) using invalid goto statements.
------------
function foo(...) {
...
$stmt = $mysql->prepare($sql);
if (!$stmt) return false;
if (!$stmt->bind_param('i', $foo)) return false;
if (!$stmt->bind_result($bar, $baz, $quux)) return false;
if (!$stmt->execute()) return false;
------------
$stmt = $mysql->prepare($sql) or return false;
$stmt->bind_param('i', $foo) or return false;
$stmt->bind_result($bar, $baz, $quux) or return false;
$stmt->execute() or return false;
------------
$stmt = $mysql->prepare($sql) or goto error;
$stmt->bind_param('i', $foo) or goto error;
$stmt->bind_result($bar, $baz, $quux) or goto error;
$stmt->execute() or goto error;
...
return true;
error: return false;
Previous Comments:
------------------------------------------------------------------------
[2015-05-13 15:49:10] someone dot wanted dot to dot be dot unknown at gmail dot com
In 2015, I'd like to ask php developers team make this feature available.
We can't write very clear code like
> <?php
> unlink() or return false;
Instead of that we forced to use huge if statement:
> <?php
> if (!unlink())
> return false;
I think community will be pleasant if we will see this feature implemented.
------------------------------------------------------------------------
[2007-03-04 04:09:31] iliaa@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
.
------------------------------------------------------------------------
[2007-03-03 18:54:25] s dot j dot t dot mocking at students dot uu dot nl
Description:
------------
"<statement> or die" works as expected, but "<statement> or return"
results in syntax errors.
Haven't found anything in the documentation which describes this behavior. If it's not a
bug, it's very counterintuitive.
Reproduce code:
---------------
This works:
function foo()
{
0 or die("bla");
}
This produces a syntax error:
function bar()
{
0 or return ("bla");
}
Expected result:
----------------
I would expect bar() to return bla
Actual result:
--------------
Parse error: syntax error, unexpected T_RETURN
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=40712&edit=1