php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44833 inconsistent operator 'or'
Submitted: 2008-04-25 16:42 UTC Modified: 2008-04-30 13:34 UTC
From: vmarsik at suse dot cz Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.5 OS: SuSE Linux
Private report: No CVE-ID: None
 [2008-04-25 16:42 UTC] vmarsik at suse dot cz
Description:
------------
$result = mysql_query($sql) or die( mysql_error() );
- works OK

$result = mysql_query($sql) or return( null );
- Parse error: syntax error, unexpected T_RETURN in xx.php on line 24

$result = mysql_query($sql) or $ret = null;
- works OK

$result = mysql_query($sql) or { $ret = null; return $ret; };
- Parse error: syntax error, unexpected '{' in xx.php on line 24

The second version should behave exactly as the first one.
The fourth probably as well.
Also applies to '||', which behaves exactly as 'or'.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-25 18:54 UTC] colder@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

return( null ) is not a value, it can't be used as one in a logical expression.
 [2008-04-30 13:34 UTC] vmarsik at suse dot cz
I quite understand the reason, and have no need to argue with you about PHP grammatics, even if I find it inconsistent at this point. Languages like Perl seem to be cleaner in this case.

If you ever considered improving PHP grammatics, this report might help.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Dec 07 13:00:01 2025 UTC