rfc:cyclic-replace
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:cyclic-replace [2015/01/09 13:54] – francois | rfc:cyclic-replace [2015/02/02 16:55] – francois | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Add cyclic string replacements ====== | ====== Add cyclic string replacements ====== | ||
- | * Version: 1.0 | + | * Version: 1.6 |
- | * Date: 2015-01-09 | + | * Creation date: 2015-01-05 |
+ | * Last modification date : 2015-02-02 | ||
* Author: François Laupretre, francois@tekwire.net | * Author: François Laupretre, francois@tekwire.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 28: | Line 29: | ||
This is what we name ' | This is what we name ' | ||
- | only when we set the option to loop in the replace array but I didn't find a better name. | + | only when we set the option to loop in the replace array. |
- | Note that replacements are done in array order. Key values are ignored. | + | Note that replacements are done in array order. Key values are ignored |
So, features brought by this RFC to str_[i]replace() are : | So, features brought by this RFC to str_[i]replace() are : | ||
Line 40: | Line 41: | ||
be a string or an array. If it is a string, we have the usual string/ | be a string or an array. If it is a string, we have the usual string/ | ||
behavior. If it is an array, cyclic replacement is performed. | behavior. If it is an array, cyclic replacement is performed. | ||
- | So, the 'array search' | + | So, the 'array search' |
' | ' | ||
- | As this is performed using recursion, search can contain any level of imbricated | ||
- | arrays, provided replace provides the corresponding structure. | ||
- | Note that, in case of multi-level | + | Arbitrarily nested subject |
- | search array as, as soon as we find a non-array replace value, this value is | + | array structure |
- | used as replacement string for the whole corresponding search subtree. The opposite | + | |
- | case is very different : If the replace | + | |
- | than 1 level, array to string conversion will occur (with E_NOTICE | + | |
- | wonderful ' | + | |
Empty replace arrays are considered as unexpected. When one is provided, an | Empty replace arrays are considered as unexpected. When one is provided, an | ||
Line 63: | Line 58: | ||
php_char_to_str_ex() and php_str_to_str_ex() (defined in ext/ | php_char_to_str_ex() and php_str_to_str_ex() (defined in ext/ | ||
take an additional //options// | take an additional //options// | ||
- | argument. This argument is not used at the moment but, this allows their API | + | argument. This argument is not used at the moment but it allows their API |
to remain compatible with the new new php_str_to_array_ex() function. | to remain compatible with the new new php_str_to_array_ex() function. | ||
Line 75: | Line 70: | ||
Now, this combination of argument types causes the search string to be replaced | Now, this combination of argument types causes the search string to be replaced | ||
- | with elements from the replace array. So, the behavior is different. | + | with elements from the replace array. |
- | The BC break is minimal here as I hope very few people ever relied on a replace | + | Different behavior too each time we meet an empty array as replace value. |
- | array being converted to ' | + | Previously, as seen above, an E_NOTICE |
- | + | ||
- | Different behavior too when replace is an empty array. Previously, as seen above, an E_NOTICE | + | |
was raised and the array was converted to ' | was raised and the array was converted to ' | ||
- | is raised and the subject is returned unchanged. | + | is raised and the subject is returned unchanged. |
- | an array as replace arg, while supported | + | |
- | (even documentation states that). | + | The support of arbitrarily-nested subject brings the same |
+ | kind of BC because previous implementations supported one array level only. | ||
+ | |||
+ | All these BC breaks are similar and deal with array to string conversions in | ||
+ | previous implementations. Can be considered | ||
+ | relying on an array-to-string conversion | ||
+ | functions, while theoritically supported, is very improbable. | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 97: | Line 96: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Extensions using one the C functions with a modified API need to be adapted (add | + | Extensions using one of the C functions with a modified API (see BC changes in C API above) |
- | a 0 argument to each call). | + | need to be adapted (adding |
+ | the whole php-src tree (outside of string.c). | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
Line 126: | Line 126: | ||
are exclusive (they cannot be combined) : | are exclusive (they cannot be combined) : | ||
- | * STR_REPLACE_STOP : Stop replacements (up to count(replace) occurences of needle can be replaced) | + | * STR_REPLACE_STOP : Stop replacements (up to count(replace) occurences of needle can be replaced) |
* STR_REPLACE_FIRST : Remaining occurences are replaced with the first element of the replace array. | * STR_REPLACE_FIRST : Remaining occurences are replaced with the first element of the replace array. | ||
* STR_REPLACE_LAST : Remaining occurences are replaced with the last element of the replace array. | * STR_REPLACE_LAST : Remaining occurences are replaced with the last element of the replace array. | ||
- | * STR_REPLACE_LOOP : Loop and restart replacements with the first element of the replace array. | + | * STR_REPLACE_LOOP : Loop and restart replacements with the first element of the replace array. |
* STR_REPLACE_EMPTY : Remaining occurences are replaced with an empty string. | * STR_REPLACE_EMPTY : Remaining occurences are replaced with an empty string. | ||
Line 149: | Line 149: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | |||
- | None | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 158: | Line 156: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | Propose the addition | + | Proposed: |
+ | |||
+ | * Add (search=null, | ||
+ | |||
+ | * Add similar | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Not sure of required | + | Required |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | Pull request against | + | Pull request against PHP7 branch : [[https:// |
- | + | ||
- | When implementation will be complete, this PR is intended to be the final patch. | + | |
===== Implementation ===== | ===== Implementation ===== | ||
Line 187: | Line 187: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | (Keep this updated with features that were discussed on the mail lists) | + | Support for arbitrarily-nested search/ |
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
rfc/cyclic-replace.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1