php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30845 add "in" operator to test for inclusion
Submitted: 2004-11-19 22:29 UTC Modified: 2004-11-20 01:55 UTC
Votes:3
Avg. Score:2.0 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: phpbugs at eire dot ca Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.2 OS: FreeBSD
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: phpbugs at eire dot ca
New email:
PHP Version: OS:

 

 [2004-11-19 22:29 UTC] phpbugs at eire dot ca
Description:
------------
Some languages such as SQL or (cough)Visual Basic(cough) include an "in" operator to test for inclusion in a given range of values.

SQL uses an explicit list of values like so:
SELECT s1 FROM t1 WHERE s1 IN (SELECT s1 FROM t2);
Or an even simpler example:
SELECT 'foo' IN ('foo','bar','foobar');

Visual Basic makes it even better by adding the ellipsis operator:
if iBar in (25..40) then

This would be a great addition to PHP, with or without the ellipsis operator.  It would be especially useful for switch statements.  And if you could pass it an array, I'd be in heaven!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-19 22:36 UTC] jed at jed dot bz
The ellipsis operator is unnecessary due to the existence of the range() function.

   true == 5 in range(1, 10);

The in operator, in my opinion, is unnecessary and is only syntactic sugar due to the existence of in_array(). I don't like S.S. operators (I opposed instanceof et. al., as well as "and" as an alternative to &&). In the long run, syntactic sugar makes code more difficult to read and just adds more passes in the parser. PHP at its root isn't BASIC.

It's nice functionality, I agree, but there's a lot more that could be done to the language to make it more like VB. And that's not a good path to start down.
 [2004-11-20 01:55 UTC] derick@php.net
in_array in combination with range() does the same. We will not add more syntax for this.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 23:01:30 2024 UTC