php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15515 Constructions involving "... or ..." don't work properly.
Submitted: 2002-02-11 21:44 UTC Modified: 2002-06-18 19:24 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: jyoung187 at hotmail dot com Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 4.0.6 OS: RH Linux 7.2 (kernel 2.4.9-21)
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: jyoung187 at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-02-11 21:44 UTC] jyoung187 at hotmail dot 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-15 13:01 UTC] 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-06-18 19:24 UTC] 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-09-04 12:23 UTC] phpuser at jvhovig dot remove dot three dot words dot com
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.
 [2004-06-20 07:36 UTC] michaelaskew at mac dot com
I'd like to second the motion to make this usage valid. 
I don't see anything in the manual that explains why 
this is invalid, but I'll conjecture that it has 
something to do with the keywords not returning a value, 
and I suppose the 'or' operator requires a value on its 
right hand side.

I should think it would be easy enough to have the 
keywords return something so this becomes valid; after 
all, the expression 'or die ...' is valid and 'die' 
doesn't really have a return value.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC