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
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: valentiny510 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Sat Apr 20 03:01:28 2024 UTC