rfc:trailing_whitespace_numerics

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
Next revisionBoth sides next revision
rfc:trailing_whitespace_numerics [2019/02/07 01:32] – missing clause ajfrfc:trailing_whitespace_numerics [2019/03/04 22:14] ajf
Line 11: Line 11:
 [[rfc:invalid_strings_in_arithmetic|Since PHP 7.1]], most parts of PHP that perform string to number conversions use the same definitions of numeric strings, and differ only in the types of errors that non-well-formed and non-numeric strings produce. According to those definitions: [[rfc:invalid_strings_in_arithmetic|Since PHP 7.1]], most parts of PHP that perform string to number conversions use the same definitions of numeric strings, and differ only in the types of errors that non-well-formed and non-numeric strings produce. According to those definitions:
  
-  * A //well-formed// numeric string contains a number optionally preceded by whitespace. For example, <php>"123"</php> is well-formed (just a number), and <php"  1.23e2"</php> is also well-formed (a number preceded by whitespace).+  * A //well-formed// numeric string contains a number optionally preceded by whitespace. For example, <php>"123"</php> is well-formed (just a number), and <php> 1.23e2"</php> is also well-formed (a number preceded by whitespace).
   * A //non-well-formed// numeric string is any string beginning with a well-formed numeric string but followed by other characters, notably including whitespace. For example, <php>"1.23e2abc"</php> is non-well-formed (a number followed by unrelated letters), and <php>"  1.23e2  "</php> (a number both preceded and followed by whitespace) is also non-well-formed.   * A //non-well-formed// numeric string is any string beginning with a well-formed numeric string but followed by other characters, notably including whitespace. For example, <php>"1.23e2abc"</php> is non-well-formed (a number followed by unrelated letters), and <php>"  1.23e2  "</php> (a number both preceded and followed by whitespace) is also non-well-formed.
   * A //non-numeric// string is a string that is neither a well-formed nor a non-well-formed numeric string. For example, <php>"abc1.23e2"</php> is non-numeric (it doesn't start with a number, nor does it start with whitespace followed by a number).   * A //non-numeric// string is a string that is neither a well-formed nor a non-well-formed numeric string. For example, <php>"abc1.23e2"</php> is non-numeric (it doesn't start with a number, nor does it start with whitespace followed by a number).
Line 44: Line 44:
 To follow on from part 1, for the next PHP x.0 (currently PHP 8.0), this RFC proposes that the concept of the “non-well-formed” numeric string be removed, and instead all such strings be treated as non-numeric. This change would break backwards-compatibility and thus is proposed for a major instead of minor PHP version. To follow on from part 1, for the next PHP x.0 (currently PHP 8.0), this RFC proposes that the concept of the “non-well-formed” numeric string be removed, and instead all such strings be treated as non-numeric. This change would break backwards-compatibility and thus is proposed for a major instead of minor PHP version.
  
-The hope is that the backwards compatibility impact would be limited by Part 1's acceptance of trailing whitespace, since that would prevent a large category of currently non-well-formed strings from being affected. The remaining cases should be rarer and code can be easily updated with the addition of explicit conversions (<php>(int)</php>, <php>(float)</php>).+The hope is that the backwards compatibility impact would be limited by Part 1's acceptance of trailing whitespace, since that would prevent a large category of currently non-well-formed strings from being affected.
  
-In order to prepare for the backwards-compatibility break in the following major version, the “A non well formed numeric value encountered” notice (where currently produced) should be changed in the PHP 7.x (currently PHP 7.4) to mention that this behaviour is deprecated, i.e. ”A non well formed numeric value encountered (non well formed numeric values are deprecated and will be considered non-numeric in PHP 8.0)”.+In order to prepare for the backwards-compatibility break in the following major version, the “A non well formed numeric value encountered” notice (where currently produced) should be changed in the next PHP 7.x (currently PHP 7.4) to mention that this behaviour is deprecated, i.e. ”A non well formed numeric value encountered (non well formed numeric values are deprecated and will be considered non-numeric in PHP 8.0)”.
  
 For the PHP interpreter, this change would be accomplished by modifying the ''is_numeric_string'' C function (and its variants) in the Zend Engine. This would therefore affect PHP features which make use of this function, including: For the PHP interpreter, this change would be accomplished by modifying the ''is_numeric_string'' C function (and its variants) in the Zend Engine. This would therefore affect PHP features which make use of this function, including:
  
-  * [[rfc:invalid_strings_in_arithmetic|Arithmetic operators]] would now produce the same <php>E_WARNING</php> as for other non-numeric strings and treat the string as having the numeric value 0+  * [[rfc:invalid_strings_in_arithmetic|Arithmetic operators]] would now produce the same <php>E_WARNING</php> as for other non-numeric strings (TBD: and return 0)
   * The <php>int</php> and <php>float</php> type declarations would produce the same <php>TypeError</php> as for other non-numeric strings   * The <php>int</php> and <php>float</php> type declarations would produce the same <php>TypeError</php> as for other non-numeric strings
   * Type checks for built-in/extension (“internal”) PHP functions would produce the same <php>E_WARNING</php> error and return NULL (weak typing mode) or the same <php>TypeError</php> (strict typing mode) as for other non-numeric strings   * Type checks for built-in/extension (“internal”) PHP functions would produce the same <php>E_WARNING</php> error and return NULL (weak typing mode) or the same <php>TypeError</php> (strict typing mode) as for other non-numeric strings
Line 56: Line 56:
 It would not affect the following features, since they already treat non-well-formed numeric strings strictly: It would not affect the following features, since they already treat non-well-formed numeric strings strictly:
  
-  * The comparison operators 
   * The <php>\is_numeric</php> function   * The <php>\is_numeric</php> function
   * The <php>++</php> and <php>--</php> operators   * The <php>++</php> and <php>--</php> operators
 +
 +TBD: comparison operators 
 +
 +TBD: what about explicit conversions, though?
  
 The PHP language specification's [[https://github.com/php/php-langspec/blob/master/spec/05-types.md#the-string-type|definition of str-numeric]] would be modified. TBD. The PHP language specification's [[https://github.com/php/php-langspec/blob/master/spec/05-types.md#the-string-type|definition of str-numeric]] would be modified. TBD.
rfc/trailing_whitespace_numerics.txt · Last modified: 2020/07/23 21:50 by ajf