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/10 19:36] – francois | rfc:cyclic-replace [2015/02/02 18:00] – francois | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Add cyclic string replacements ====== | ====== Add cyclic string replacements ====== | ||
- | * Version: 1.5 | + | * Version: 1.6 |
* Creation date: 2015-01-05 | * Creation date: 2015-01-05 | ||
- | * Last modification date : 2015-01-10 | + | * Last modification date : 2015-02-02 |
* Author: François Laupretre, francois@tekwire.net | * Author: François Laupretre, francois@tekwire.net | ||
* Status: Under discussion | * Status: Under discussion | ||
Line 29: | 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 in replace arrays. | Note that replacements are done in array order. Key values are ignored in replace arrays. | ||
Line 44: | Line 44: | ||
' | ' | ||
- | Arbitrarily nested subject arrays are now supported, returning exactly the same array structure and preserving keys. Only | + | Arbitrarily nested subject arrays are now supported, returning exactly the same |
- | values are replaced. | + | array structure and preserving keys. Only values are replaced. |
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 58: | 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 77: | Line 77: | ||
is raised and the subject is returned unchanged. | is raised and the subject is returned unchanged. | ||
- | The support of multi-level arrays as search, replace, and subject brings the same | + | The support of arbitrarily-nested |
kind of BC because previous implementations supported one array level only. | kind of BC because previous implementations supported one array level only. | ||
- | So, if provided with multi-level arrays, array to string conversion would have | ||
- | been performed. | ||
All these BC breaks are similar and deal with array to string conversions in | All these BC breaks are similar and deal with array to string conversions in | ||
- | previous implementations. | + | previous implementations. |
relying on an array-to-string conversion (with E_NOTICE) when calling these | relying on an array-to-string conversion (with E_NOTICE) when calling these | ||
- | functions, while theoritically supported, | + | functions, while theoritically supported, |
- | improbable. | + | |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 129: | 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 153: | Line 150: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | ==== Support of arbitrarily-nested search array ==== | + | The need for an additional options arg is still under discussion. |
- | + | ||
- | As search array support is now performed using recursion, search can contain | + | |
- | any level of nested arrays, | + | |
- | + | ||
- | Note that, in case of multi-level arrays, replace array can be less deep than | + | |
- | search array as, as soon as we find a non-array replace value, this value is | + | |
- | used as replacement string for the whole corresponding search subtree. | + | |
- | case is very different : If the replace array tree is deeper than the search tree by more | + | |
- | than 1 level, array to string conversion will occur (with E_NOTICE and the | + | |
- | wonderful ' | + | |
- | + | ||
- | Recursion also extends the behavior of ' | + | |
- | implementation supported only one-level arrays | + | |
- | + | ||
- | This feature | + | |
- | to 1 level (allow array of strings only) and, as a consequence, | + | |
- | one more level than search. | + | |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 180: | Line 160: | ||
Proposed: | Proposed: | ||
- | * Add (search=null, | + | * Add (search=null, |
* Add similar features (cyclic replacement and multi-level array recursion) to preg_replace() and preg_filter(). | * Add similar features (cyclic replacement and multi-level array recursion) to preg_replace() and preg_filter(). | ||
Line 186: | Line 166: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Required majority : probably 2/3. | + | Required majority : 50%+1. |
===== 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 211: | Line 189: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | (Keep this updated with features that were discussed on the mail lists) | + | Support for arbitrarily-nested search/ |
rfc/cyclic-replace.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1