rfc:explicit_octal_notation

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:explicit_octal_notation [2020/11/07 08:33] – Add explicit mention of upper case notation. girgiasrfc:explicit_octal_notation [2021/01/04 20:12] (current) – Change status to implemented and specify links girgias
Line 3: Line 3:
   * Date: 2020-10-20   * Date: 2020-10-20
   * Author: George Peter Banyard, <girgias@php.net>   * Author: George Peter Banyard, <girgias@php.net>
-  * Status: Under Discussion+  * Status: Implemented (https://git.php.net/?p=php-src.git;a=commit;h=589bdf30b2bea10172a49bcad26d44b18f192556)
   * First Published at: https://wiki.php.net/rfc/explicit_octal_notation   * First Published at: https://wiki.php.net/rfc/explicit_octal_notation
  
 ===== Introduction ===== ===== Introduction =====
  
-PHP's literal octal notation can lead to some confusing results such as <php>"016" == 016</php> evaluating to false. This is because ''016'' is evaluated as an octal integer and resolves to ''14''.+PHP's literal octal notation can lead to some confusing results such as <php>16 === 016</php> evaluating to false. This is because ''016'' is evaluated as an octal integer and resolves to ''14''.
  
 This convention for octal integers is well established and followed by many programming languages (Java, C, C#, Golang, Haskell, and more). However, Python, JavaScript, and Rust [[https://docs.python.org/3/reference/lexical_analysis.html#integer-literals|[1]]][[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]][[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] only accept or support an explicit octal notation ''0o''. This convention for octal integers is well established and followed by many programming languages (Java, C, C#, Golang, Haskell, and more). However, Python, JavaScript, and Rust [[https://docs.python.org/3/reference/lexical_analysis.html#integer-literals|[1]]][[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]][[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] only accept or support an explicit octal notation ''0o''.
Line 35: Line 35:
 <blockquote>supporting octal numbers is not possible, because handling the string '0123' as the number 83 would be highly unexpected for end users of an application.</blockquote> <blockquote>supporting octal numbers is not possible, because handling the string '0123' as the number 83 would be highly unexpected for end users of an application.</blockquote>
  
-Therefore, this RFC has no impact on numeric strings.  ''"0o16"'' is still interpreted as a string and only a string.+Numeric strings in PHP are //always// decimal. Analogous to the example from the introduction <php>"016" == 016</php> evaluates to false as <php>(int) "016"</php> evaluates to ''16''
 + 
 +This RFC has no impact on the behaviour of numeric strings.  ''"0o16"'' would still be interpreted as a string and only a string. Moreover, <php>(int) "0o16"</php> will continue to evaluate to ''0''.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 41: Line 43:
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-Next PHP 8.x.+PHP 8.1.
  
 ===== RFC Impact ===== ===== RFC Impact =====
Line 60: Line 62:
   * Deprecate the implicit octal notation.   * Deprecate the implicit octal notation.
   * Support hexadecimal, octal, and binary numbers in strings   * Support hexadecimal, octal, and binary numbers in strings
 +  * Add a flag for the <php>FILTER_VALIDATE_INT</php> filter to only allow octals with the explicit octal notation.
  
-===== Proposed Voting Choices =====+===== Voting Choices =====
  
 Per the Voting RFC, there is a single Yes/No vote requiring a 2/3 majority for this proposal to be accepted. Per the Voting RFC, there is a single Yes/No vote requiring a 2/3 majority for this proposal to be accepted.
Line 78: Line 81:
 ===== Implementation ===== ===== Implementation =====
  
-After the project is implemented, this section should contain  +Merged into PHP 8.1 
-  - the version(s) it was merged into +  - Commit: https://git.php.net/?p=php-src.git;a=commit;h=589bdf30b2bea10172a49bcad26d44b18f192556
-  - a link to the git commit(s)+
   - a link to the PHP manual entry for the feature   - a link to the PHP manual entry for the feature
   - a link to the language specification section (if any)   - a link to the language specification section (if any)
rfc/explicit_octal_notation.txt · Last modified: 2021/01/04 20:12 by girgias