#15515 [Com]: Constructions involving "... or ..." don't work properly.

From: Date: Wed, 04 Sep 2002 17:23:29 +0000
Subject: #15515 [Com]: Constructions involving "... or ..." don't work properly.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18436@lists.php.net to get a copy of this message
 ID:               15515
 Comment by:       phpuser@jvhovig.remove.three.words.com
 Reported By:      jyoung187@hotmail.com
 Status:           Bogus
 Bug Type:         Compile Failure
 Operating System: RH Linux 7.2 (kernel 2.4.9-21)
 PHP Version:      4.0.6
 New Comment:

While the "failures" reported here are not a bug, it would be a highly
desirable feature to have this in the language, and I respectfully
request the PHP development team add it to a future version of the
language.

In particular, I would very much enjoy the ability to do the
following:

  isset($x) or return false;
  ($x > 0) or echo "failure";
  empty($x) or break;
  ereg($x, $y) or continue;

The ability to perform the four lines of code above would add greatly
to the readability and clarity of PHP code.

In the case of the "echo" statement, I am aware that print() function
works instead, but would still enjoy the use of the echo construct in
that fashion.


Previous Comments:
------------------------------------------------------------------------

[2002-06-18 19:24:43] sniper@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



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

[2002-02-15 13:01:35] sander@php.net

This is a dupe... I'm sure I read a bug about this before, but I can't
find it...
Anyway, 'or return' doesn't.

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

[2002-02-11 21:44:24] jyoung187@hotmail.com

Script:

<?php
function foo() {
  $result = mysql_query("SELECT 1") or return false;  //fails
  print("foo") or return false; // fails
  print("foo") or return 0; // fails
  print("foo") or return(false); // fails
  $result = mysql_query("SELECT 1") or die(); // works
}
?>

This bug seems to be present in PHP versions 4.0.6, and 4.2.0 - it's
been tried on more than one machine (including two that I haven't
installed myself).  Essentially, constructions involving <expr1> or
<expr2>, where expr2 is a keyword (return, continue, break, etc) fail
with a parse error, whereas constructions where expr2 is a function
(such as die() etc) succeed.  This bug is not specific to the "or"
keyword, either.  It also occurs with the "and" keyword.

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


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



Thread (5 messages)

« previous php.bugs (#18436) next »