php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76140 Allow multiple comparisons in expressions
Submitted: 2018-03-23 02:35 UTC Modified: 2018-03-23 08:11 UTC
From: valentiny510 at gmail dot com Assigned:
Status: Suspended Package: Variables related
PHP Version: 7.2.3 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
27 + 50 = ?
Subscribe to this entry?

 
 [2018-03-23 02:35 UTC] valentiny510 at gmail dot com
Description:
------------
Currently to compare if a variable have some (?:exact)? value we need to use arrays or enumerate a list of all values + the variable name itself, Ex:

$a = true;
if ($a === 'a' || $a === 'b' || $a === 'c') # etc...
	print 'true';
else
	print 'false';

IMHO will be very very handy if we can evaluate them all in a single expression like this:

if ($a === ('a'||'b'||'c') # ...

is much cleaner and easier to read and understand the whole sentence


Test script:
---------------
$a = 'a';
if ($a === ('a'||'b'||'c'))
	print 'true';
else
	print 'false';


Expected result:
----------------
true

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-23 08:11 UTC] requinix@php.net
-Status: Open +Status: Suspended
 [2018-03-23 08:11 UTC] requinix@php.net
That's already valid code. There would have to be a new syntax for this.

But it won't happen in this bug reporting tool because this is too significant of an addition. It would have to go through the RFC process, which begins by talking about this on the internals mailing list.
https://wiki.php.net/rfc/howto
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 03:01:29 2024 UTC