rfc:in_operator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:in_operator [2015/03/15 00:37] – removed integer support kelunikrfc:in_operator [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: In Operator ====== ====== PHP RFC: In Operator ======
-  * Version: 0.5+  * Version: 0.5.1
   * Date: 2015-03-15   * Date: 2015-03-15
   * Authors: Niklas Keller <me@kelunik.com>, Bob Weinand <bobwei9@hotmail.com>   * Authors: Niklas Keller <me@kelunik.com>, Bob Weinand <bobwei9@hotmail.com>
-  * Status: Under Discussion+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/in_operator   * First Published at: http://wiki.php.net/rfc/in_operator
  
 ===== Introduction ===== ===== Introduction =====
-This RFC adds a new ''in'' operator which simplifies ''contains'' checks for strings and arrays. Currently, we have to use ''in_array($needle, $haystack, true)'' or ''strpos($haystack, $needle) !== false''. These functions have a inconsistent parameter order, so it's hard to remember which is the right one for each. The ''in'' operator makes these checks way more readable and lowers the cognitive load. Additionally, it also works for ''Traversable''.+This RFC adds a new ''in'' operator which simplifies ''contains'' checks for strings and arrays. The ''in'' operator makes these checks way more readable and lowers the cognitive load. Additionally, it also works for ''Traversable''
 + 
 +===== Motivation ===== 
 +Checking if a specific input in an allowed range of value is a very common check in web application, therefore this operator simplifies those checks (and besides makes them a little bit faster). Currently, we have to use ''in_array($needle, $haystack, true)'' or ''strpos($haystack, $needle) !== false''. These functions have a inconsistent parameter order, so it's hard to remember which is the right one for each. Additionally, omitting the third parameter for ''in_array'' is very common which led to security vulnerabilities in the past.
  
 ===== Proposal ===== ===== Proposal =====
Line 61: Line 64:
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-New reserved keyword ''in''. This affects function, constant, class and method names.+New reserved keyword ''in''. This affects function, constant and class**but not** class constant and method names, because it depends on the context sensitive lexer being merged.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 78: Line 81:
 ===== Votes ===== ===== Votes =====
 Requires a 2/3 majority. Even if it passes, it will //only// get merged if the [[rfc/context_sensitive_lexer|context sensitive lexer]] gets merged. Requires a 2/3 majority. Even if it passes, it will //only// get merged if the [[rfc/context_sensitive_lexer|context sensitive lexer]] gets merged.
 +
 +<doodle title="Introduce the in operator?" auth="kelunik" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +Voting started on 2015-03-15 and ends on 2015-03-29.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
rfc/in_operator.1426379832.txt.gz · Last modified: 2017/09/22 13:28 (external edit)