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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun May 05 03:01:29 2024 UTC