rfc:array-to-string

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:array-to-string [2015/01/11 23:02] francoisrfc:array-to-string [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Improve array to string conversion ====== ====== Improve array to string conversion ======
-  * Version: 1.1+  * Version: 2.1
   * Creation date: 2015-01-10   * Creation date: 2015-01-10
-  * Last modification date : 2015-01-11 +  * Last modification date : 2016-02-02 
-  * Author: François Laupretre, francois@tekwire.net +  * Author: François Laupretre, <francois@tekwire.net> 
-  * Status: Under discussion+  * Status: Withdrawn
   * First Published at: http://wiki.php.net/rfc/array-to-string   * First Published at: http://wiki.php.net/rfc/array-to-string
 +
 +This RFC is withdrawn because discussion shows that the subject is far from mature
 +and potential side effects require more discussions. It will probably be revived
 +in the future but potential BC breaks reserve such changes for a major release.
  
 ===== Introduction ===== ===== Introduction =====
Line 19: Line 23:
 E_NOTICE and 'Array'. E_NOTICE and 'Array'.
  
-consider this as +We consider this as no more than temporary half-backed solution : we raise a low-level error 
-a half-backed solution : we raise an error, which is not a 'real' +and we return a useless string.
-error (an E_WARNING would be) and we return a useless string (anybody relying on the 'Array' value, please call me :). +
-Off topic: I am personally against the existence of E_NOTICE and E_STRICT, which +
-are, IMO, half-backed solutions too.+
  
-The only possible justification I imagine for the current behavior is to have +Now, the release of a new major version is the occasion to make definitve decision.
-stopped flame war or for (wrong) BC reasons.+
  
-Now, the release of a new major version is the occasion to get rid of problematic +  Note: the RFC originally proposedeither to fully support the feature, or to deprecate it
-behaviors we have been pulling behind us for years+  Following discussion, it was decided to only propose the option of deprecating it. 
- +  So the other option was removed, and can be consulted via older versions of the RFC.
-I think of two possible alternative and opposite behaviors :+
  
 ==== 1st alternative: deprecate ==== ==== 1st alternative: deprecate ====
  
 Here, we consider that array-to-string conversion was never actively supported nor Here, we consider that array-to-string conversion was never actively supported nor
-encouraged and that it is time to disable it definitely.+encouraged, that, it most cases, its only effect is hiding bugs, and that it is time to disable it definitely.
  
-As noone ever agreed on 'standard' way to convert an array to a string, the only +Another argument is that there never was an agreement on the 'standard' way 
-clean solution is to really disable it.+to convert an array to a string.
  
-Array-to-string conversion will be considered like object-to-string with no 'toString' method: +So, we propose that Array-to-string conversions are considered exactly the same 
-any conversion attempt generates a 'fatal catchable error'. Then, +as object-to-string with no '__toString' method: 
-if the program is still alive, the conversion returns 'Array' as before.+any conversion attempt generates an E_RECOVERABLE_ERROR. Then, 
 +if the program is still alive, the conversion returns 'Array' as before. The E_NOTICE 
 +message is suppressed. 
 +No more worries about hiding bugs with this logic, as masking such an error level is a strong 
 +user decision, definitely not the same as disabling E_NOTICE.
  
-We could go through a migration phase with an E_DEPRECATED but the 5.7 release was rejected +We could go through a migration phase using E_DEPRECATEDbut we consider 
-and we already raise an E_NOTICE. If 5.7 is revivedwe'll replace the E_NOTICE +that, since an E_NOTICE is currently generatedit may be considered as a 
-with E_DEPRECATED butotherwise, this phase can probably be skipped.+deprecation noticeand we can directly switch to E_RECOVERABLE_ERROR.
  
-==== 2nd alternative: full support ====+Another argument is that, while this one should not be very problematic, it is 
 +always better to introduce a BC break in a major version.
  
-Here, we decide that array-to-string conversion is a valid concept. We define a +If 5.7 is revived, it will contain an interim version, with E_NOTICE replaced by E_DEPRECATED.
-standard algorithm to perform the conversionfix it in stone and +
-encourage C and PHP code to use it with no restriction.+
  
-Of course, the first step is to remove the E_NOTICE. +==== 2nd alternative: full support ====
- +
-The 2nd step is the choice of the conversion algorithm. We could for instance +
-convert the array to a +
-recursive concatenation of every non-array elements of the +
-array tree, each of them converted to a string (a recursive implode() with no 'glue'). +
-Array elements would be taken in array order, keys would be ignored.+
  
-Existing rules for non-array types to string conversions would be applied to all +  Removed
-non-array members of the input array.+
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-If we deprecate array-to-string, we consider that array to string conversion +The potential BC breaks 
-is an error. We just don't tolerate this error anymore. The BC break is +are important because a lot of PHP code runs in E_NOTICE-disabled environments and
-important because a lot of PHP code runs in E_NOTICE-disabled environments and+
 the 'Array' return value, while probably invalid, may easily go unnoticed. the 'Array' return value, while probably invalid, may easily go unnoticed.
  
-If we add full support, the removal of E_NOTICE has no impact. Andas all of us +In balance of thiswe can consider that raising the error level in environments 
-probably agree that anybody relying on the 'Array' string should choose another profession+where E_NOTICE messages are disabledwill generally help discovering bugs that had 
-the overall BC break is minimal.+remained unnoticed because the error level was hidden. 
 + 
 +Actuallyduring the discussion, the opinions seemed to converge towards 
 +the position that discovering undetected bugs is probably more important than 
 +potential BC breaks.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
  
-PHP 7+7.0
  
 ===== RFC Impact ===== ===== RFC Impact =====
  
-Touches every explicit or implicit array-to-string conversionsin C or PHP code.+Touches every explicit or implicit array-to-string conversionwhether called 
 +from extensions or in PHP code.
  
 ===== Open Issues ===== ===== Open Issues =====
  
-None (yet)+None
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-No other zval type conversion should be impacted.+No other type conversion is impacted.
  
 ===== Future Scope ===== ===== Future Scope =====
Line 99: Line 98:
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
  
-Required majority 2/3and even probably more :)+Basic Yes/No Yes to replace E_NOTICE with E_RECOVERABLE_ERRORNo for no change.
  
-===== Patches and Tests =====+<doodle title="array-to-string" auth="francois" voteType="single" closed="false"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
-Implementation is easy.+Voting will close March 6th, 00:00 (UTC).
  
-Patches and tests will be written as soon as we seem to agree on something.+Required majority : 2/3 of voters. 
 + 
 +===== Patches and Tests ===== 
 + 
 +Patch provided, fixing existing tests is under way.
  
 ===== Implementation ===== ===== Implementation =====
Line 116: Line 122:
 ===== References ===== ===== References =====
  
-PR for comments : https://github.com/php/php-src/pull/991+PR : https://github.com/php/php-src/pull/991 
 + 
 +32 tests are broken by this change. The coresponding fixes are under way and not 
 +included in the PR.
  
 ===== Rejected Features ===== ===== Rejected Features =====
rfc/array-to-string.1421017369.txt.gz · Last modified: 2017/09/22 13:28 (external edit)