rfc:str_contains

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:str_contains [2020/02/17 11:58]
philippta
rfc:str_contains [2020/08/01 23:41] (current)
carusogabriel RFC was implemented
Line 3: Line 3:
   * Date: 2020-02-17   * Date: 2020-02-17
   * Author: Philipp Tanlak, philipp.tanlak@gmail.com   * Author: Philipp Tanlak, philipp.tanlak@gmail.com
-  * Status: Under Discussion+  * Status: Implemented
   * First Published at: http://wiki.php.net/rfc/str_contains   * First Published at: http://wiki.php.net/rfc/str_contains
  
Line 35: Line 35:
 str_contains("abc", "a"); // true str_contains("abc", "a"); // true
 str_contains("abc", "d"); // false str_contains("abc", "d"); // false
 +
 +// $needle is an empty string
 +str_contains("abc", "");  // true
 +str_contains("", "");     // true
 </code> </code>
 +
 +Regarding empty string values as $needle:
 +<blockquote>As of PHP 8, behavior of "" in string search functions is well defined, and we consider "" to occur at every position in the string, including one past the end. As such, both of these will (or at least should) return true. The empty string is contained in every string. - Nikita Popov</blockquote>
  
  
Line 42: Line 49:
 In a recent discussion in the internals mailing list, we came to the conclusion, there is no need for a multibyte variant of this function (e.g. ''mb_str_contains''). The reason behind this is: A multibyte variant of this function would behave no different than the non-multibyte function. Multibyte variants behave differently when the offset/position has relevance at which the string was found. As this is not the case for this function, there is no need for that. In a recent discussion in the internals mailing list, we came to the conclusion, there is no need for a multibyte variant of this function (e.g. ''mb_str_contains''). The reason behind this is: A multibyte variant of this function would behave no different than the non-multibyte function. Multibyte variants behave differently when the offset/position has relevance at which the string was found. As this is not the case for this function, there is no need for that.
  
-Concerning the case-insensitivity for this function: This might be a feature for the future, as the relevance for that is much less compared to the case-sensitive function. With that in mind, the only valid variants would be str_contains/mb_str_icontains. I assume PHP developers would be confused if this RFC offered such inconsistant variants of this function, so it's better to start small and iterate upon that. +Concerning the case-insensitivity for this function: This might be a feature for the future, as the relevance for that is much less compared to the case-sensitive function. With that in mind, the only valid variants would be str_contains/mb_str_icontains. I assume PHP developers would be confused if this RFC offered such inconsistent variants of this function, so it's better to start small and iterate upon that. 
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 53: Line 60:
 PHP 8 PHP 8
  
 +===== Voting =====
 +<doodle title="Add str_contains as described" auth="philippta" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Implementation ===== ===== Implementation =====
 The ''str_contains'' function has been implemented in this pull request: The ''str_contains'' function has been implemented in this pull request:
 https://github.com/php/php-src/pull/5179 https://github.com/php/php-src/pull/5179
rfc/str_contains.1581940697.txt.gz · Last modified: 2020/02/17 11:58 by philippta