|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-03 18:54 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
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;